33

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

Peeter Joot
  • 7,848
  • 7
  • 48
  • 82
Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
  • 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. – GWW May 14 '11 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. – Andrew Spott May 16 '11 at 02:21
  • Add an `'--enable-optimized'` option to `./configure` script of llvm – osgx May 18 '11 at 02:01
  • I think it is common in this case to answer the question yourself, and then accept it. – haggai_e Jun 12 '11 at 13:16

5 Answers5

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.

Pieter
  • 17,435
  • 8
  • 50
  • 89
  • 1
    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`. – Martin Braun Jun 22 '23 at 08:04
16

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).

JCx
  • 2,689
  • 22
  • 32
idbrii
  • 10,975
  • 5
  • 66
  • 107
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.

Andrew Spott
  • 3,457
  • 8
  • 33
  • 59
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
Misty
  • 416
  • 3
  • 8
  • 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.) https://github.com/dart-lang/ffigen/pull/402#issuecomment-1154348670 – Daco Harkes Jun 14 '22 at 13:47
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])
Cameron Lowell Palmer
  • 21,528
  • 7
  • 125
  • 126