Building clang on Mavericks with libc++....

Hi,

  when compiling clang (todays trunk) from source on Mavericks, which ships with libc++ in:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/

and for LLVM configured like this:

$ /Users/rdm/root/interpreter/llvm/src/configure --prefix=/Users/rdm/root/interpreter/llvm/inst --disable-docs --disable-bindings --disable-visibility-inlines-hidden --enable-libcpp --disable-optimized --enable-targets=host --with-extra-options= CC=clang CXX=clang++ CFLAGS=-m64 CXXFLAGS=-m64

but that does not seem to be enough as the built clang++ does look for libc++ in:

$ echo | ./interpreter/llvm/inst/bin/clang++ -E -v -x c++ -
clang version 3.4
Target: x86_64-apple-darwin13.0.0
Thread model: posix
  "/Users/rdm/root/interpreter/llvm/inst/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -E -disable-free -main-file-name - -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -resource-dir /Users/rdm/root/interpreter/llvm/inst/bin/../lib/clang/3.4 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/rdm/root -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o - -x c++ -
clang -cc1 version 3.4 based upon LLVM 3.4svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/Users/rdm/root/interpreter/llvm/inst/bin/../lib/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
  /usr/local/include
  /Users/rdm/root/interpreter/llvm/inst/bin/../lib/clang/3.4/include
  /usr/include
  /System/Library/Frameworks (framework directory)
  /Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 171 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

so what config option should I specify to get clang++ to use the one and only copy of libc++, namely the one in:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/

Should configure not take the libc++ location from the specified CXX compiler? Which indeed is:

$ echo | clang++ -E -v -x c++ -Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -E -disable-free -disable-llvm-verifier -main-file-name - -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/rdm/root -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o - -x c++ -
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
  /usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
  /usr/include
  /System/Library/Frameworks (framework directory)
  /Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 167 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2

Any suggestions welcome.

Cheers, Fons.

Since Xcode 5 (or Maverick, I'm not sure), libc++ headers are no longer part of the system, but part of the toolchain.

So Maverick does not ships with C++ header, clang in Xcode does (and it know where to look for its own libc++ headers). If you are using your own clang build, you have to provide libc++ headers yourself.

Actually, this is easy as it is done automatically by the build system if libcxx is checked out in <llvm source>/projects/

For the record, libcxx can be checked out using :

svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx

-- Jean-Daniel

Hi Jean-Daniel,

  thanks for the reply. However, it seems putting the libcxx <llvmsource>/projects/ does not work, as shown in config.log:

configure:3639: WARNING: Unknown project (libcxx) won't be configured automatically
configure:3680: checking build system type

and even in projects/Makefile it says:

# Don't build libcxx, it isn't designed to be built directly.
DIRS := $(filter-out libcxx,$(DIRS))

so what is the best approach to inject:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/

as search directory to self compiled clang?

Cheers, Fons.

It looks like the headers are only copied during make install, so you
have to install clang to be able to use the libcxx headers.

Hi Rafael,

   Could you elaborate a bit more on how to get the libc++ headers copied during clang's make install? I don't see that happening now.

Cheers, Fons.

It worked out of the box for me by checking out libcxx into
llvm/projects. Note that the headers are installed to
<inst>/lib/c++/v1/

Cheers,
Rafael

Hi Jean-Daniel,

thanks for the reply. However, it seems putting the libcxx /projects/ does not work, as shown in config.log:

configure:3639: WARNING: Unknown project (livcxx) won’t be configured automatically

configure:3680: checking build system type

and even in projects/Makefile it says:

Don’t build libcxx, it isn’t designed to be built directly.

DIRS := $(filter-out libcxx,$(DIRS))

It is expected. The copy of the headers is driven by a Makefile in llvm/tools/clang/runtime/libcxx/
It only copies the headers during the install step and does not try to rebuild the libc++ binary.

so what is the best approach to inject:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/

as search directory to self compiled clang?

Cheers, Fons.

Hi,

when compiling clang (todays trunk) from source on Mavericks, which ships with libc++ in:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/

and for LLVM configured like this:

$ /Users/rdm/root/interpreter/llvm/src/configure --prefix=/Users/rdm/root/interpreter/llvm/inst --disable-docs --disable-bindings --disable-visibility-inlines-hidden --enable-libcpp --disable-optimized --enable-targets=host --with-extra-options= CC=clang CXX=clang++ CFLAGS=-m64 CXXFLAGS=-m64

but that does not seem to be enough as the built clang++ does look for libc++ in:


so what config option should I specify to get clang++ to use the one and only copy of libc++, namely the one in:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/

Should configure not take the libc++ location from the specified CXX compiler? Which indeed is:

Any suggestions welcome.

Cheers, Fons.

Since Xcode 5 (or Maverick, I’m not sure), libc++ headers are no longer part of the system, but part of the toolchain.

So Maverick does not ships with C++ header, clang in Xcode does (and it know where to look for its own libc++ headers). If you are using your own clang build, you have to provide libc++ headers yourself.

Actually, this is easy as it is done automatically by the build system if libcxx is checked out in /projects/

For the record, libcxx can be checked out using :

svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx

– Jean-Daniel


Org: CERN, European Laboratory for Particle Physics.
Mail: 1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248
WWW: http://fons.rademakers.org Fax: +41 22 7669640

– Jean-Daniel

# Don't build libcxx, it isn't designed to be built directly.
DIRS := $(filter-out libcxx,$(DIRS))

It is expected. The copy of the headers is driven by a Makefile in
llvm/tools/clang/runtime/libcxx/
It only copies the headers during the install step and does not try to
rebuild the libc++ binary.

It would be nice to figure out a way to have clang work from the build
directory. I used to bootstrap it by using one build dir to build the
next, but now I have to install stage1 first :frowning:

Cheers,
Rafael