compilation c code failed because libxml2 library is missing on my iMac sonoma

I'm trying to compile a C-code for research (sac seismic analysis), and the compilation require libxml2 libraries which obviously are missing on my iMac (Sonoma 14.7.1). No libxml in /usr/lib or usr/local/lib.

How can I implement them or are those librairies hidden somewhere?


Thanks for you help

Christel

iMac 27″, macOS 14.7

Posted on Nov 26, 2024 2:21 AM

Reply
9 replies

Nov 27, 2024 8:39 AM in response to christel184

Apple moved ~everything into the Xcode app bundle and related a while back, and away from having one set of includes in a traditional spot. This to allow several different SDKs to be installed in parallel, and to also allow easier updates. They added some knobs to make that work better, though.


IIRC…


Set the SDK path you are using, akin to this:

https://andreasfertig.blog/2021/02/clang-and-gcc-on-macos-catalina-finding-the-include-paths/


Related, useful in your login script:

export SDKROOT="`xcrun --show-sdk-path`"


I changed something to get command-line builds working a while back too, but am not entirely certain what, and will be back to the Mac to check that later today.

Nov 26, 2024 2:29 PM in response to christel184

I haven't done anything with X11 XTerm in ages, so cannot comment on compilation suite behavior in that environment. It would seem to me that you should find the xml2 bits in these locations that clang should just find on macOS 15.1.1 using the Command Line Tools for Xcode 16.1. I don't have a Sonoma installation at this time, but would expect the libXML stuff to be in the most recent locations for the last SDKs installed there.


Include

/Library/Developer/CommandLineTools/SDKs/MacOSX15.1.sdk/usr/include/libxml2/libxml


Library

/Library/Developer/CommandLineTools/SDKs/MacOSX15.1.sdk/usr/lib/libxml2.2.tbd


No need to install libxml2 from a package manager.


Nov 27, 2024 10:04 AM in response to christel184

Just to clarify, both Xcode and the Command Line tools already have all of the necessary settings to compile code using libxml2. There is no need to manipulate or even look at SDK settings. Download one of the examples and build it with something like:


clang -o tree tree.c -lxml2


For any other problems, the most likely cause would be some crazy complicated open source build system that was last tested on a Mac in 2008. This isn't even "extremely common", it's standard procedure that these open source projects won't build on a Mac because they were done incorrectly. These days, more and more projects are directing people to install Homebrew, which only makes this problem worse.

Nov 27, 2024 10:23 AM in response to etresoft

I do use homebrew sparingly and apparently at one time, I migrated from an Intel Time Machine backup to an ARM platform and performing your tree compilation example above, it found the homebrew installed libxml2.2.dylib in a /usr/local/lib path and understandably blew up when it encountered that X86_64 dylib.


Then I had to do the following:


clang -o tree tree.c -L /Library/Developer/CommandLineTools/SDKs/MacOSX15.1.sdk/usr/lib -lxml2


to get a clean compile whose executable dumped a tree from a supplied XML document. I have since wiped that old homebrew X86_64 library location. I could have also removed the X86_64 libxml2.dylib before applying your compilation example without forcing the library location above.

Nov 26, 2024 3:37 AM in response to christel184

It depends on whether you are using Apple's Developer tools (Xcode or Command Line Tools for Xcode), or some other compilation suite (e.g. GNU C) or IDE. If any dependencies were installed with a package manager (homebrew, MacPorts, etc.) and your code depends upon them, you need to refer to those libraries and include instructions.


The current Xcode and command line tools for Xcode install libxml2 in their respective lib and include locations.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

compilation c code failed because libxml2 library is missing on my iMac sonoma

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.