How to add libz and libiconv?

I have these errors:

clang: error: no such file or directory: ‘/usr/lib/libz.dylib’

clang: error: no such file or directory: ‘/usr/lib/libiconv.dylib’

Command Ld failed with a nonzero exit code

These errors go away if I go to “Other Linker Flags” in Xcode and remove the above two lines for each build type, and replace them with -lz and -liconv.

The problem is, that each time I run the following command, the linker flags get replaced :


Is there a solution so one does not have to manually replace the flags with -lz and -liconv each time we run the above command ?

You really should use the search functionality on this forum before posting.

See if this helps:

Thanks for your reply, I did use the search functionality and found that post, but was unable to understand the solution, and for some reason could not post any message on that thread. I followed the link as well, but still could not make sense of it.

As I could not post any reply to that thread, I asked a fresh question. I apologise for any inconvenience.

What the solution is, is still unclear to me though. If you have a moment, can you please explain?

Edit: perhaps there was some problem with my browser, as I was unable to post any reply to that thread earlier. Apologies for any inconvenience caused.

Edit: I tried again. Still do not have the ability to post to that thread.

You need to spend some time learning how CMake works, otherwise you’re just going to keep running into these problems.

The posts explain what you need to do, which is to add the find_library lines to your CMakeLists.txt in the section where it has “if (APPLE)” :

For example:

    find_library(libiconv NAMES libiconv)
    find_library(libz NAMES libz)

I did read that post, and did add those lines, but adding them by itself didn’t seem to do anything. The same error show up:

clang: error: no such file or directory: ‘/usr/lib/libz.dylib’
clang: error: no such file or directory: ‘/usr/lib/libiconv.dylib’

The only way I have found to make them go away is by manually adding -lz and -liconv flags, which is why I was asking. I am using the simulator, and that thread seems to indicate it works only for device builds…

Can you please post your CMakeLists.txt file ?

My cmake files won’t help you, since I’ve ported my projects to use ADXE (a Cocos2d-x v4 fork), which doesn’t have any of these problems.

ok, any idea how to solve the libz libiconv problem ? Adding those lines does not seem to solve it, and so far the only solution I seem to have is adding -lz and -liconv flags manually, which is time consuming…