iPhone libxml2 not found during build

2019-02-06 05:23发布

问题:

I currently got some errors with libxml2 in my iPhone project. This was working before, after making some changes in my build properties building failed. (libxml2.dylib is added in the build phases)

#import <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/xmlstring.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>

I've added the following items to the Build Settings:

Other Linker Flags: -lxml2
Header Search Paths: /usr/include/libxml2

I've tried adding them to the project and targets (at the same time, and switching between them) without any difference.

I also tried adding the following to the Header Search Path:

${SDKROOT}
${SDK_DIR}

Both with no result.

Building fails for: iPhone device iPhone and iPad emulator

Anyone have an idea?

I'm using the GData Objective-C client library: http://code.google.com/p/gdata-objectivec-client/ I'm compiling the source files directly into my project and followed all the steps that are given in the wiki. When manually importing the libxml headers again, XCode suggests the following:

#import <libxml2/libxml/tree.h>

Which doesn't work either.

回答1:

Add ${SDKROOT}/usr/include/libxml2 as a header search path instead of only ${SDKROOT}.

Watch out that you all build targets that need libxml get the extra search path. If you add the path to your project's build settings, all its targets will inherit it and there shouldn't be a problem.



回答2:

  • Add libxml2.dylib in Build Phases.
  • Add TFHpple.m, TFHppleElement.m, XpathQuery.m to Build Phases (Compile Sources).
  • Add
    Other Linker Flags: -lxml2 
    Header Search Paths: ${SDK_DIR}/usr/include/libxml2

in PROJECT --> Build Phases and in TARGETS --> Build Phases.