100

I am getting following errors.

libxml/tree.h no such file or directory

I have already added libxml2.dylib to my project, however I am getting this type of trouble. Please help me.

Daniel Alder
  • 5,031
  • 2
  • 45
  • 55
sagarkothari
  • 24,520
  • 50
  • 165
  • 235

22 Answers22

214

Follow the directions here, under "Setting up your project file."

Setting up your project file

You need to add libxml2.dylib to your project (don't put it in the Frameworks section). On the Mac, you'll find it at /usr/lib/libxml2.dylib and for the iPhone, you'll want the /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/lib/libxml2.dylib version.

Since libxml2 is a .dylib (not a nice friendly .framework) we still have one more thing to do. Go to the Project build settings (Project->Edit Project Settings->Build) and find the "Search Paths". In "Header Search Paths" add the following path:

$(SDKROOT)/usr/include/libxml2

Also see the OP's answer.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • 12
    Don't do what that says when it asks you to add "/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/include/libxml2" to the Header Search Path. Add "/usr/include/libxml2 instead. That makes your project independent of specific SDKs. – cdespinosa Sep 16 '09 at 00:27
  • That works just so long as there's actually a symlink to it in `/usr/include`. I haven't tried installing libxml2 so I can't confirm default behavior. But yes, it's much better to link it that way. – Matt Ball Sep 16 '09 at 13:59
  • 1
    When developping under XCode, GCC uses the -isysroot option that relocates the root of the SDK. If you add /usr/include/libxml2 in the header search paths, it will be translated at compilation time to the usr/include/libxml2 folder INSIDE the current SDK. – Laurent Etiemble Apr 16 '10 at 15:53
  • When i set this "$(SDKROOT)/usr/include/libxml2" to the Header Search Path (XCode 4.2), than it says that " "_OBJC_METACLASS_$_UIResponder", referenced from: _OBJC_METACLASS_$_D2GAppDelegate in MyDemoAppDelegate.o ld: symbol(s) not found for architecture i386". What can i do? – NicTesla Apr 29 '12 at 14:09
  • 1
    Great. thanks. i was missing '$(SDKROOT)' which created problems. –  May 10 '12 at 06:31
  • not sure why but I had to add this($(SDKROOT)/usr/include/libxml2") in Target Settings instead of Project build settings – Sourabh Bhardwaj Mar 26 '14 at 11:02
86

Adding libxml2 in Xcode 4.3 / 5 / 6

Adding libxml2 is a big, fat, finicky pain in the ass. If you're going to do it, do it before you get too far in building your project.


You need to add it in two ways:

1. Target settings

Click on your target (not your project) and select Build Phases.

Click on the reveal triangle titled Link Binary With Libraries. Click on the + to add a library.

Scroll to the bottom of the list and select libxml2.dylib. That adds the libxml2 library to your project.

2. Project settings

Now you have to tell your project where to look for it three more times.

Select the Build Settings tab.

Scroll down to the Linking section. Under your projects columns double click on the Other Linker Flags row. Click the + and add -lxml2 to the list.

Still more.

In the same tab, scroll down to the Search Paths section.

Under your projects column in the Framework Search Paths row add /usr/lib/libxml2.dylib.

In the Header Search Paths and the User Header Search Paths row add $(SDKROOT)/usr/include/libxml2.

In those last two cases make sure that path is entered in Debug and Release.

3. Clean

Under the Product Menu select Clean.

Then, if I were you (and lets face it, I probably am) I'd quit Xcode and walk away. When you come back and launch you should be good to go.

Community
  • 1
  • 1
e.w. parris
  • 1,093
  • 10
  • 11
  • Thanks, this was the only solution that worked for me with Xcode 4.3.3 – lifjoy Jun 26 '12 at 23:05
  • 1
    These step-by-step instructions were the only once that worked for me (Xcode 4.4.1). Thanks! – Frank Sep 04 '12 at 15:08
  • Worked for me without setting the Framework search paths in Xcode 4.1.1 – Richard Garside Sep 12 '12 at 15:31
  • Using Xcode 4.5.1 do not set the Framework search path. Solved my issue otherwise though. I don't know what I'd do without SO. – Dancreek Oct 09 '12 at 21:18
  • I found this after I worked out the problem: I had renamed XCode (having multiple versions concurrently) and had included a space in the application name - the quoting of "$(SDKROOT)" is what fixed it because otherwise the compilation step just did a split on the string and passed -I flags for each half. – misnomer Oct 18 '12 at 19:58
  • THough it did not work for me, however I bumped you up for thorough instructions, you can hardly find those on stackoverflow. I have XCode4.6 and, apparently, in this version you just dont put $(SDKROOT) infront of the path, if you have this issue, you just leave it like this: "/usr/include/libxml2" and it only works like that in XCode 4.6. How do you like them apples. uhhh. here is the link to the post about that: http://stackoverflow.com/questions/14622684/import-libxml-tree-h-file-not-found-after-xcode-update – Boris Gafurov Feb 22 '13 at 16:50
  • Works for me on xCode 4.6.3. Thanks!! – capikaw Aug 25 '13 at 13:15
  • After adding one more setting to make it working "Always search user path = YES" then it worked for me !! – i_Intiution Nov 26 '13 at 16:59
  • Sorry to say,but it is not working in Xcode 5.0.2. I tried in the same way what you did. There is no use to me. Can u please help me.. – Ganesh Jan 09 '14 at 05:28
  • 1
    `opening import file 'Swift.swift': Not a directory` after doing this in Xcode 5. – User Oct 05 '14 at 16:39
  • Oh and I'm trying to use the Obj-C library in Swift. – User Oct 05 '14 at 17:23
  • On step 2, "Select the Build Settings tab": AND make sure the ALL is selected not Basic, otherwise the User Search Path will not appear. – Adriano Spadoni Feb 11 '15 at 13:43
  • 1
    I also got the error "opening import file for module 'Swift': Not a directory". To fix this just don't add "/usr/lib/libxml2.dylib" to "Framework Search Paths". Still worked for me after I ignored that step. – Daniel Ryan May 07 '15 at 03:39
22

For Xcode 6, I had to do the following:

1) add the "libxml2.dylib" library to my project's TARGET (Build Phases -> Link Binary With Libraries)

2) add "$(SDKROOT)/usr/include/libxml2" to the Header Search Paths on the TARGET (Build Settings -> Header Search Paths)

After this, the target should build successfully.

Andy Shephard
  • 1,726
  • 17
  • 26
19

You also need to add /usr/include/libxml2 to your include path.

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
11

Form the link of @Matt Ball,

I found following helpful to me.

You need to add libxml2.dylib to your project (don't put it in the Frameworks section). On the Mac, you'll find it at /usr/lib/libxml2.dylib and for the iPhone, you'll want the /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/lib/libxml2.dylib version.

Since libxml2 is a .dylib (not a nice friendly .framework) we still have one more thing to do. Go to the Project build settings (Project->Edit Project Settings->Build) and find the "Search Paths". In "Header Search Paths" add the following path on the Mac:

 /usr/include/libxml2 
sagarkothari
  • 24,520
  • 50
  • 165
  • 235
11

Ray Wenderlich has a blog post about using gdata that solves this problem. Basically these simple steps:

In XCode, click Project\Edit Project Settings and make sure “All Configurations” are checked.

Find the Search Paths\Header Search Paths setting and add /usr/include/libxml2 to the list.

Finally, find the Linking\Other Linker Flags section and add -lxml2 to the list.

original post: read and write xml documents with gdataxml

NANNAV
  • 4,875
  • 4
  • 32
  • 50
bennythemink
  • 5,096
  • 4
  • 36
  • 54
  • 2
    Found this answer in many places, but all of them forgot to mention that it is the Header search path on the project, not on the target. Thanks a lot for explaining it properly. – esbenr Aug 12 '11 at 13:03
7

I found the same, I had to add $(SDKROOT)/usr/include/libxml2 for the latest Xcode (4.3.x). ALSO, what kept me circling around for hours is the fact that I was modifying the "TARGET" and not the "PROJECT" (the new UI of Xcode is so intricate that its easy to overlook this). You need to modify the PROJECT!

Mike
  • 71
  • 1
  • 1
5

Another solution. do all the steps in header search path etc. and make sure your selected configuration in project in Project settings is the correct one. When you double click on project build settings ,you may be changing in Distribution settings, But you are trying to add header search path in "Debug" settings. So make sure you are in correct settings. or choose all settings

S.P.
  • 5,427
  • 11
  • 56
  • 83
4

I found that with xCode 4.3.2 I had to enter $(SDKROOT)/usr/include/libxml2 into the Header Search field rather than simply /usr/include/libxml2

fsharp
  • 319
  • 2
  • 4
4

As of Mavericks (OS X 10.9) the /usr/include directory is gone. Half of the answers here are obsolete, as the application will not compile until you sort out the include directory.

I solved the problem creating a symbolic link to MacOSX SDK in terminal, using the following command:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include

The application now compiles again.

Legoless
  • 10,942
  • 7
  • 48
  • 68
  • Exactly what I was looking for. This works perfect. Just make sure in your header search paths you put /usr/include/libxml2 – Josh Bernfeld Oct 14 '14 at 08:00
3

On Mountain Lion I was facing same issue, which was resolved by adding /usr/include/libxml2 to include paths with flag "recursive", use this if all above is not fruitful.

Aqib Mumtaz
  • 4,936
  • 1
  • 36
  • 33
3

I'm not sure what the difference is but add the include path to the project as well as the target.

pschang
  • 2,568
  • 3
  • 28
  • 23
2

Also select "Always Search User Paths" to YES. In XCode 4.3.3 its by default NO

Atif
  • 1,220
  • 11
  • 16
2

Please follow the following steps

  1. Adding libxml2
    libxml2.dylib can be found on your mac machin at /usr/lib/libxml2.dylib

  2. Change "Header Search Paths"
    Click on [Project Name] (in left panel) -> Project -> Build Settings -> Select All (default is Basic)
    Type Header Search Paths in search box
    Double click on Header Search Paths -> + -> "$(SDKROOT)/usr/include/libxml2"

  3. Add -lxml2 to "Other linker flag"
    Search for "Other Linker Flags" as search in step 2
    click on the "Other Linker Flags" row. Click the "+" and add "-lxml2" to the list.

  4. Change your project type to ARC -> No i.e Automatic Reference Counting to No You can search ARC as per in step 2

Bo.
  • 2,547
  • 3
  • 24
  • 36
mandar
  • 21
  • 3
2

Xcode 4.5 I have used The CW's solution entirely. The only exception is that $(SDKROOT)/usr/include/libxml2 didn't work for me, and I had to add "$(SDK_DIR)"/usr/include/libxml2 to my Projects Header Search Paths and User Header Search Paths. After that project builds successfully.

EDIT: I have Google GData project inside my project (called MyProject) (my project uses). GData requires libxml. To build project MyProject successfully, I add "$(SDK_DIR)"/usr/include/libxml2 to Header Search Paths of MyProject and no to Header Search Paths of GData . If I didnt add it to MyProject, project did not build).

Petr
  • 836
  • 1
  • 14
  • 37
2

I found this visual tutorial useful.

Luca
  • 9,259
  • 5
  • 46
  • 59
Frank Fu
  • 3,483
  • 2
  • 28
  • 38
2

I had this problem when I reopened a project (which was developed on XCode 3.something on Leopard) after upgrading to Snow Leopard and XCode 3.2. Curious enough, it only affected some kinds of builds (emulator builds went fine, device ones gave me the error). And I have libxml2 at /usr/include, and it indeed contains libxml/tree.h.

Even the magic "Clean" did not work, but "Empty Caches..." under the "XCode" menu (between the Apple logo and File) did the trick (was that menu there in previous versions?). Beats me the reason, but after a clean there were no more complaints regarding libxml/tree.h

chesterbr
  • 2,940
  • 3
  • 29
  • 26
1

Blockquote Adding libxml2 in Xcode 4.3.x

Adding libxml2 is a big, fat, finicky pain in the ass. If you're going to do it do it before you get too far in building your project.

Here's how.

Target settings

Click on your target (not your project) and select "Build Phases". Click on the reveal triangle titled "Link Binary With Libraries". Click on the "+" to add a library. Scroll to the bottom of the list and select "libxml2.dylib". That adds the libxml2 library 2 your project… but wait.

Project settings

Now you have to tell your project where to look for it three more times.

Select the "Build Settings tab". Scroll down to the "Linking" section. Under your project's columns double click on the "Other Linker Flags" row. Click the "+" and add "-lxml2" to the list.

Still more.

In the same tab, scroll down to the "Search Paths" section. Under your project's column in the "Framework Search Paths" row add "/usr/lib/libxml2.dylib".

In the "Header Search Paths" AND the "User Header Search Paths" row add "$(SDKROOT)/usr/include/libxml2". In those last two cases make sure that path is entered in Debug AND Release.

Then. Under the "Product" Menu select "Clean".

This is working and for Xcode5 too! Thank you!

Denko
  • 11
  • 1
  • 1
    This is not working in Xcode 5.0.2. I made above changes to my project, but no luck. Can u help me what needs to be done. – Ganesh Jan 09 '14 at 06:19
1

Don't put libxml2.dylib under frameworks folder put it under root just below the root(Top left blue icon )

Then Click on the Project (TOP Left blue icon) ,GO to Build Settings,in the search box type "Header Search Paths" and then add the this "$(SDKROOT)/usr/include/libxml2"

This code resolve my issue hope it will help you fix this

Ranjan
  • 9
  • 3
1

@Aqib Mumtaz - I got it working by following the instructions in Parris' note above entitled "Adding libxml2 in Xcode 4.3 / 5 / 6". The step in using a Framework Search Path does not work and the compiler complains. Big kudos to that fella anyway!

I am using Xcode 6.2b3

Regardless of the version of Xcode you are using, it is buggy. Don't always assume that compile errors are real. There are many times when it does not follow header search paths and includes clearly listed are not found. Worse, the errors that result tend to point you in different directions so you waste a lot of time dinking around with distractions. With that said...

Recommend baby steps by starting with this exactly...:

  1. create a single window Mac OS X Cocoa project called "Bench Test"
  2. add XpathQuery into your project source directory directly in the Finder
  3. click on the tiny folder icon under the project window's red close button
  4. drag XpathQuery (folder if you contained it) into the project assets on the left of the project window's display
  5. drag /Applications/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libxml2.2.dylib into your project assets, at the bottom. This will add it into your "Build Phases" -> "Link Binary With Libraries" the easy way
  6. click on the "Bench Test" project icon in the project assets column, top of the left
  7. search for "Other Linker Flags" under "Build Settings"
  8. add "-lxml2" (sans "") to "Other Linker Flags" under the "Bench Test" project icon column
  9. search for "header search" under "Build Settings"
  10. add "$(SDKROOT)/usr/include/libxml2" (sans "") to "Header Search Paths" under the "Bench Test" project icon column
  11. add "$(SDKROOT)/usr/include/libxml2" (sans "") to "User Header Search Paths" under the "Bench Test" project icon column

Notes:

  • Mine would not work until I added that search path to both "Header Search Paths" and "User Header Search Paths".
  • To get to the libxml2.2.dylib in the finder, you will need to right click your Xcode icon and select "Show Package Contacts" (editorial: what a hack.. cramming all that garbage into the app)
  • Be prepared to change the linked libxml2.2.dylib. The one inside Xcode is intentionally used to ensure that Xcode gets something it knows about and in theory was tested. You may want to use the dylib in the system later (read up in this thread)
  • As I am using Xcode 6.2b3, I may have a newer libxml2.2.dylib. Yours could be named slightly different. Just search the folder for something that starts with "libxml" and ends with ".dylib" and that should be it. There may also be an alias like "libxml2.dylib". Don't use that right away as resolving an alias adds another variable into the Xcode "what could have bugs" equation.
  • For sanity sake, I make aliases of the external libraries, rename them to indicate which one they are, and keep them at the same level as the project file in the Finder. If they change location, change name, etc, the alias will have in it's Get Info, the original file's full path for later detective work to get the project compiling and linking again. (symlinks break too easy and are not natural to the Mac)
  • Last thing, and very important, see http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html where you can download XpathQuery and get some more goodness.

hope this helps.

If you happen to be developing something for Veterans, oh say an iPhone / iPad or Mac app, and are working against something called "MDWS" or "VIA" which are SOAP based interfaces to the medical record system... please contact me

Cerniuk
  • 14,220
  • 2
  • 29
  • 27
0

I solved in three steps inXcode 8.0 + Unit Test Project

1) I added libxml file to the Build Phases.follow this link

2) I added Other Linker Flags as -ObjC (For both project and test project targets)

3) I setup Header Search Path as "${SDKROOT}/usr/include/libxml2" (Don't forget double quote in either side) (For both project and test project targets)

One of them will solve the issue. If not you have to apply all three of the above.

Community
  • 1
  • 1
Zumry Mohamed
  • 9,318
  • 5
  • 46
  • 51
0

i tought i added wrongly, then i realize the problem is it not support arc, so check the support one here, life saver -> http://www.michaelbabiy.com/arc-compliant-gdataxml-library/

Bhimbim
  • 1,348
  • 2
  • 19
  • 15