0

您好,我想在我的项目中使用 Google Maps API,并且添加了 libz.dylib。当我在其他链接器标志中写入-ObjC链接 Google Maps API 时,它运行良好,但是当我删除此标志 tan -lz library is not found 时发现错误,所以请帮我解决这个问题。

4

1 回答 1

2

Short Answer
Leave the -ObjC flag there where it is.


Long Answer
According to the Google Maps SDK docs for iOS, the -ObjC flag is required.

In the Other Linker Flags section, add -ObjC. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.

If you want more insight, please refer to the Apple technical Q&A QA1490

The problem arises with categories on static libraries, which are not linked by default

Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.

Apparently Google Maps APIs make use of categories on their static library, therefore you need the -ObjC flag to change the linker behavior, as explained in the Q&A

To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.

于 2013-06-18T11:17:22.350 回答