36

I looked in the usual places (/usr/lib/,/Developer/usr/lib/,/usr/local/lib), and it isn't there.

If it isn't installed, does anyone know where I can find instructions to install it?

Thanks!

I'm not sure if I should close this, but I found the answer I was looking for:

In OS X, with XCode 4 installed, libclang.dylib is at /Developer/usr/clang-ide/lib/libclang.dylib

4
  • 1
    One small tip, I recommend that you install the latest version of clang (if you haven't already) the one bundled with OSX is quite outdated. Commented May 14, 2011 at 15:27
  • @GWW: Do you know any good tutorials for doing so? the LLVM and CLANG websites are geared toward compiling and installing the debug version of clang, not a release version, and I don't know the configure flag to change that. Commented May 16, 2011 at 2:21
  • Add an '--enable-optimized' option to ./configure script of llvm Commented May 18, 2011 at 2:01
  • I think it is common in this case to answer the question yourself, and then accept it. Commented Jun 12, 2011 at 13:16

5 Answers 5

28

With the latest (appstore) XCode 4.3.2, the location changed, it can now be found in

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib 

The /Developer directory, among others, no longer exists by default. Everything is now packaged inside the XCode application, so that delta updates from the appstore work.

Sign up to request clarification or add additional context in comments.

4 Comments

Note that you can't link it to /usr/lib, because this is a read-only system. However you can link it to /usr/local/lib/ like so: sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib /usr/local/lib. Most build systems will still manage to pick it up. It was missing for me when compiling Rust's implementation of opencv.
@MartinBraun that command replaced my /usr/local/lib folder with a link to libclang.dylib. My system is now completely broken.
@BrandonDyer man ln. If you copied my command, this can't happen the way you describe it. sudo ln -s will not replace the target /usr/local/lib, if it already exists. If it does, and it is a folder, it will create the link within the target, instead. I would agree that a trailing / in my command would make it safer, but then again you recklessly added -f to my command without thinking when there was some error. Excuse my harsh comment, but don't just run commands blindly on the internet, especially when adding a -f flag to it. It's a good lesson. Try recover from Time Machine. GL.
I didn't use -f. My comment about "my system is completely broken" was a bit misleading, I'll admit. It more just broke some of my builds because it was expecting a folder where there was now a file.
19

You can always do a search of your filesystem. There are several ways.

On a Mac with Spotlight this is probably the best:

mdfind -name libclang.dylib 

However most UNIX systems also have a locate database, which can be searched easily:

locate libclang.dylib 

And when all else fails you can iterate through the file system (rather slowly) using find:

find / -type f -name libclang.dylib -o -name libclang.so 

You'll get some errors about unreadable locations because they're only readable by root, but that's fine (hide these errors with 2> /dev/null).

2 Comments

Or "mdfind -name libclang.dylib", which is a ton quicker :)
Or locate libclang.dylib, for a third option.
9

I found the answer:

In OS X, with XCode 4 installed, libclang.dylib is at /Developer/usr/clang-ide/lib/libclang.dylib

This is just posted for those who are interested in the answer.

Comments

2

On macOS Catalina (newest, as of posting) you can find it in the Xcode application, here:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib 

As well as outside of it if you just use Command Line Tools and you don't have Xcode.app installed, here:

/Library/Developer/CommandLineTools/usr/lib/libclang.dylib 

As pointed out by @Daco Harkes the Xcode library does not include the Objective C headers, so you might want to use the Command Line Tools version anyway.

Additionally, this uses Apple's build of Clang which can be... quirky and doesn't implement all the newest features. So you might want to download the LLVM version, which you can download from their website or get from Homebrew's LLVM package (brew install llvm).

When installed through Homebrew the library can be found at:

/usr/local/opt/llvm/lib/libclang.dylib 

1 Comment

Please note that the Command Line Tools has the Objective C headers pre-included, but the Xcode one doesn't. (If one was interested in parsing ObjectiveC as well.) github.com/dart-lang/ffigen/pull/402#issuecomment-1154348670
0

In the Xcode.app bundle

cd /Applications/Xcode.app find `pwd` -name libclang.dylib 

Typically, two copies:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib /Applications/Xcode.app/Contents/Frameworks/libclang.dylib 

In conjunction with Python and after pip install clang

import sys import clang.cindex library_path = '/Applications/Xcode.app/Contents/Frameworks' clang.cindex.Config.set_library_path(library_path) index = clang.cindex.Index.create() translation_unit = index.parse(sys.argv[1]) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.