Hello I want to use Google Maps API in my project and I have added libz.dylib. When I write -ObjC
in other linker flag for linking Google Maps API, its working well but when I remove this flag tan -lz library is not found error found, so please help me to solve this problem.

- 17,406
- 5
- 50
- 71

- 15
- 2
- 6
-
1check my answer below. Any reason to take that flag away? Also I have say that "please solve this problem" is definitely the wrong attitude to approach this community. – Gabriele Petronella Jun 18 '13 at 11:19
-
that's the point. That method is probably defined in a category which is not linked without the `-ObjC` flag. Refer to my answer below – Gabriele Petronella Jun 18 '13 at 11:41
-
I don't understand whether it works with the flag or not. You're saying a lot of different things here – Gabriele Petronella Jun 18 '13 at 11:54
-
it that's the case you may want to checkout one of the many questions about that error, which is not related to the `-ObjC` flag: http://stackoverflow.com/questions/9803702/ld-library-not-found-for-lz?rq=1, http://stackoverflow.com/questions/7815174/ld-library-not-found-for-lz-1-2-3?rq=1 – Gabriele Petronella Jun 18 '13 at 12:01
-
after adding -ObjC to other linker flag I got errors Undefined symbols for architecture armv7: "_inflate", referenced from: +[NSData(GTMZlibAdditionsPrivate) gtm_dataByInflatingBytes:length:isRawData:] in GoogleMaps(GTMNSData+zlib.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation) – Kuldeep singh Jun 18 '13 at 12:22
1 Answers
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.

- 106,943
- 21
- 217
- 235