Question

I am using libxml2 in my application and having been linking it dynamically. It works fine until I started noticing the dynamic lib was updated on 10.9 OSX and when the application runs on 10.8 and 10.7 I see issues due to lower version of libxml2. The Problem seen is Warning: program compiled against libxml 209 using older 207 I seem to get parse errors with this however the same code works fine in 10.9 with version 209

To avoid this problem, I wanted to statically compile my code to use libxml2.a. I ran into multiple issues with this. I could not compile due to missing symbols in libxml2.a version installed in my machine.

I download the latest code from git repo and compiled it. I did not install it but made my program point to the new static library. Still I have the same issue.

Compile Flags
Ld /devel/Build/Products/Debug/SecurityCoreUpdater normal x86_64
    cd /devel/BPSUpdater
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/devel/Build/Products/Debug -F/devel/Build/Products/Debug -filelist /devel/Build/Intermediates/BPSUpdater.build/Debug/BPSUpdater.build/Objects-normal/x86_64/SecurityCoreUpdater.LinkFileList -mmacosx-version-min=10.7 /devel/libxml2.a -lCF_LSXClient

Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
      _xmlIconvWrapper in libxml2.a(encoding.o)
  "_libiconv_close", referenced from:
      _xmlFindCharEncodingHandler in libxml2.a(encoding.o)
      _xmlCharEncCloseFunc in libxml2.a(encoding.o)
  "_libiconv_open", referenced from:
      _xmlFindCharEncodingHandler in libxml2.a(encoding.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there a fix for this? I am quite confused as to how to resolve this problem. I would hate to change the parser library just for this. This mean I need to rewire a lot of code. Please help.

Regards, Varun

Was it helpful?

Solution

I found the answer that there is a need to add libiconv.a if linking statically in Other Linker Flags in Build Settings or add libiconv.dylib in "Link Binary with Libraries" in "Build Phase" in xcode5. Similarly I also noticed the need to include liblzma as either dynamic lib or static to solve the issue.

Most import consideration when add as dynamic library (dylib) is the order in which the libs are present. Apparently, libiconv and liblzma must come below libxml2.a for it to compile correctly. I am not sure why this is needed but I was able to solve the problem using the same procedure. I however statically compiled all three libraries as I did not want to run into this dynamic lib version changes between OS since my installer does not check for installed version of libraries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top