Installing libc++

Howard, et. all,

Following the steps here: http://libcxx.llvm.org/

I’m stuck here:

Where it says: “That should result in a libc++.1.dylib. To install it I like to use links instead of copying, but either should work:”

Instead I get:

Jon-Kalbs-MacBook-Pro:lib jonkalb$ sudo ./buildit

  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/algorithm.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/bind.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/chrono.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/condition_variable.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/exception.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/future.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/hash.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/ios.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/iostream.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/locale.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/memory.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/mutex.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/new.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/random.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/regex.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/stdexcept.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/string.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/strstream.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/system_error.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/thread.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/typeinfo.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/utility.cpp
  • for FILE in ‘…/src/*.cpp’
  • clang++ -c -g -Os -fPIC -nostdinc++ -I…/include …/src/valarray.cpp
  • cc algorithm.o bind.o chrono.o condition_variable.o exception.o future.o hash.o ios.o iostream.o locale.o memory.o mutex.o new.o random.o regex.o stdexcept.o string.o strstream.o system_error.o thread.o typeinfo.o utility.o valarray.o -fPIC -o libc++.so.1.0 -shared -nodefaultlibs -Wl,-soname,libc++.so.1 -lpthread -lrt -lc
    ld: unknown option: -soname
    collect2: ld returned 1 exit status

Any idea what I’m doing wrong?

Jon

Hi Jon,

It looks like for some reason the following step:

$ export TRIPLE=-apple-

didn't take. You can confirm whether or not this happened with:

$ printenv

which should list:

TRIPLE=-apple-

Howard

There is no reason you have to use sudo to build the library.

For security reason, sudo cleanup the environment by default. So the "buildit" script is executed in a clean env without TRIPLE exported.

-- Jean-Daniel

If I don't use sudo I get this:

Jon-Kalbs-MacBook-Pro:lib jonkalb$ ./buildit
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -arch i386 -arch x86_64 -std=c++0x -U__STRICT_ANSI__
-nostdinc++ -I../include ../src/algorithm.cpp
/usr/bin/lipo: can't create output file: algorithm.o (Permission denied)
clang: error: unable to remove file: algorithm.o: can't destroy file:
Permission denied
clang: error: lipo command failed with exit code 1 (use -v to see
invocation)

Jon

Howard, et. all,

Following the steps here: http://libcxx.llvm.org/

I¹m stuck here:

Where it says: ³That should result in a libc++.1.dylib. To install it I like
to use links instead of copying, but either should work:²

Instead I get:

Jon-Kalbs-MacBook-Pro:lib jonkalb$ sudo ./buildit
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/algorithm.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/bind.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/chrono.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include
../src/condition_variable.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/exception.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/future.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/hash.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/ios.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/iostream.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/locale.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/memory.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/mutex.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/new.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/random.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/regex.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/stdexcept.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/string.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/strstream.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/system_error.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/thread.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/typeinfo.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/utility.cpp
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/valarray.cpp
+ cc algorithm.o bind.o chrono.o condition_variable.o exception.o future.o
hash.o ios.o iostream.o locale.o memory.o mutex.o new.o random.o regex.o
stdexcept.o string.o strstream.o system_error.o thread.o typeinfo.o
utility.o valarray.o -fPIC -o libc++.so.1.0 -shared -nodefaultlibs
-Wl,-soname,libc++.so.1 -lpthread -lrt -lc
ld: unknown option: -soname
collect2: ld returned 1 exit status

Any idea what I¹m doing wrong?

Jon

Hi Jon,

It looks like for some reason the following step:

$ export TRIPLE=-apple-

didn't take. You can confirm whether or not this happened with:

$ printenv

which should list:

TRIPLE=-apple-

Howard

You are correct. TRIPLE wasn't defined although the command was in my shell
history. In any case I executed it again and verified with:

Jon-Kalbs-MacBook-Pro:lib jonkalb$ export TRIPLE=-apple-
Jon-Kalbs-MacBook-Pro:lib jonkalb$ printenv
TERM_PROGRAM=Apple_Terminal
TERM=xterm-color
SHELL=/bin/bash
TMPDIR=/var/folders/+H/+HrzLvNcEXOJDia4To7fRk+++TI/-Tmp-/
Apple_PubSub_Socket_Render=/tmp/launch-8yXakD/Render
TERM_PROGRAM_VERSION=273.1
OLDPWD=/opt/libcxx
USER=jonkalb
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-zyZoPt/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
TRIPLE=-apple-
PWD=/opt/libcxx/lib
LANG=en_US.UTF-8
ll=ls -aFl
SHLVL=1
HOME=/Users/jonkalb
LOGNAME=jonkalb
DISPLAY=/tmp/launch-4RaTPQ/org.x:0
_=/usr/bin/printenv

Unfortunately, I'm still seeing this:

Jon-Kalbs-MacBook-Pro:lib jonkalb$ sudo ./buildit
+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/algorithm.cpp
+ for FILE in '../src/*.cpp'

Several lines omitted...

+ for FILE in '../src/*.cpp'
+ clang++ -c -g -Os -fPIC -nostdinc++ -I../include ../src/valarray.cpp
+ cc algorithm.o bind.o chrono.o condition_variable.o exception.o future.o
hash.o ios.o iostream.o locale.o memory.o mutex.o new.o random.o regex.o
stdexcept.o string.o strstream.o system_error.o thread.o typeinfo.o utility.o
valarray.o -fPIC -o libc++.so.1.0 -shared -nodefaultlibs
-Wl,-soname,libc++.so.1 -lpthread -lrt -lc
ld: unknown option: -soname
collect2: ld returned 1 exit status

Still stuck,

Jon

It looks like you don't have write permission in the directory where you've checked out libc++. You should check out into some place where you would normally do development work.

Let us know if I've guessed wrong.

Howard

The first build using sudo create the object file with owner "root", and so prevent execution of the builtit command as normal user. Restart from a fresh check out.

-- Jean-Daniel

Fix Your Permission:

// On Debian Sid Linux with /usr/local/bin/clang++ and /usr/local/bin/clang from daily rebuilds:

// assuming your group is the same as your username, therefore $sudo chown owner:group -R ./ would be $sudo chown owner:owner -R ./.

$ sudo chown username:username -R ./ inside the /buildTopLevel Path

CMake Option:

I do a CMake build outside of /libc++ parallel to /libc++ as /cmake-libc++

username@host:/path-To/cmake-libc++/$ cmake …/libc++ && make -j3

Of course inside CMakeCache.txt I can set the CXX and CC compilers to /usr/local/bin/clang++ and /usr/local/bin/clang to use the latest trunk
Clang builds I build prior to rebuild libc++.

username@host:/path-To/cmake-libc++/$ cmake -DCMAKE_CXX_COMPILER=/usr/local/bin/clang++ -DCMAKE_CXX_COMPILER=/usr/local/bin/clang …/libcxx/ && make -j3

//make -j3 (N=3: N-1= actual number of cores.) If I had 12 cores I’d really be thrilled at how quickly it builds.

Or you can just vim your CMakeCache.txt file and update those paths yourself by hand.

$vim CMakeCache.txt and edit the CMAKE_CXX_COMPILER=/usr/local/bin/clang++ by hand.

Second Option:

Doing a straight ./buildit inside the /libc++ would have me do the following:

username@host:/path-To/libc++$ sudo chown username:username -R ./

username@host:/path-To/libc++/lib/$ ./buildit

the buildit script defaults to GCC but you can change that to Clang as well:

Line 17: CXX=/usr/local/bin/clang++

Obviously, this approach is not pleasing as $CXX will change as your system updates. Debian has g++ → g+±4.6 and just modifying the buildit
file each it ever gets updated by LLVM source is less than optimal, or having it look for clang++ in your local or system path [lots of devs don’t like
installing into their /usr/local path for ``pollution reasons’’] nor is resetting your CXX path. Cmake makes it convenient, besides allowing an install
path option whose prefix I set to /usr/local.

Of course, the testit tests don’t pass as I have yet to figure out how to set them in the CMakeCache.txt file seeing as the tests aren’t locally
installable under /usr/local that I’ve found, and thus the header files to import aren’t imported correctly when compiling the source and thus leaving
it to fail the tests.

username@host:/path-To/libc++/tests/$ ./testit

Excerpt:
^
1 error generated.
piecewise.pass.cpp failed to compile
rv_pair_U_V.pass.cpp:16:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
rv_pair_U_V.pass.cpp failed to compile
swap.pass.cpp:16:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
swap.pass.cpp failed to compile
types.pass.cpp:18:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
types.pass.cpp failed to compile
U_V.pass.cpp:16:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
U_V.pass.cpp failed to compile
failed 12 tests in /home/mdriftmeyer/DeveloperProjects/LLVMProject/libcxx/test/utilities/utility/pairs/pairs.pair
comparison.pass.cpp:21:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
comparison.pass.cpp failed to compile
make_pair.pass.cpp:14:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
make_pair.pass.cpp failed to compile
non_member_swap.pass.cpp:16:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
non_member_swap.pass.cpp failed to compile
failed 3 tests in /home/mdriftmeyer/DeveloperProjects/LLVMProject/libcxx/test/utilities/utility/pairs/pairs.spec
swap_array.pass.cpp:17:10: fatal error: ‘utility’ file not found
#include
^
1 error generated.
swap_array.pass.cpp failed to compile
swap.pass.cpp:17:10: fatal error: ‘utility’ file not found
#include

Thanks Howard, you guessed right.

This is my testit result (summary):

I would've expected significantly fewer test failures for clang -std=c++0x -stdlib=libc++:

Thanks Howard, you guessed right.

This is my testit result (summary):

****************************************************
Results for /Users/jonkalb/Documents/development/developement/libcxx/test:
using Apple clang version 2.0 (tags/Apple/clang-138) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
with -std=c++0x -stdlib=libc++
----------------------------------------------------
sections without tests : 1
sections with failures : 153
sections without failures: 910
                      + ----
total number of sections : 1064
----------------------------------------------------
number of tests failed : 1221
number of tests passed : 3019
                      + ----
total number of tests : 4240
****************************************************

Is this what I should expect?

I would've expected significantly fewer test failures for clang -std=c++0x
-stdlib=libc++:

****************************************************
Results for /test:
using Apple clang version 2.0 (trunk 125236) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
with -std=c++0x -stdlib=libc++ -arch x86_64 -U__STRICT_ANSI__ -I../include
/usr/lib/libc++.dylib
----------------------------------------------------
sections without tests : 1
sections with failures : 74
sections without failures: 989
                       + ----
total number of sections : 1064
----------------------------------------------------
number of tests failed : 215
number of tests passed : 4023
                       + ----
total number of tests : 4238
****************************************************

However it has been a couple of months since I actually ran the full test
suite (been busy elsewhere). Did you get libc++abi.dylib from here:

http://home.roadrunner.com/~hinnant/libcppabi.zip

?

http://libcxx.llvm.org/ says:

To build on Mac OS X 10.6, you need a helper library and header found here.
cp cxxabi.h to /usr/include, and cp libc++abi.dylib to /usr/lib.

This library implements things like exception handling. Lack of this library
might explain your failure rate.

If that isn't it, email me privately your entire results and I'll take a look.

Howard

I noticed this difference in our reports:

using Apple clang version 2.0 (tags/Apple/clang-138) (based on LLVM 2.9svn)

using Apple clang version 2.0 (trunk 125236) (based on LLVM 2.9svn)

I think I was getting the clang++ in /usr/lib/ instead of in
/Users/jonkalb/Documents/development/developement/build/Debug+Asserts/bin/

Could that be the issue? I've changed my PATH so I now get:

Jon-Kalbs-MacBook-Pro:test jonkalb$ which clang++
/Users/jonkalb/Documents/development/developement/build/Debug+Asserts/bin/cl
ang++

and I'm running testit again. I will send the entire result to you off-list
if it isn't closer to your result.

Thanks.

Jon

Is it on purpose that the testit script didn't include the -U__STRICT_ANSI__ flags (this flag was added to buildit to workaround some issue in darwin headers).
Adding this flag will lower the count of failed tests.

FWIW, I got this with a fresh build.

using clang version 3.0 (trunk 130088)
Target: x86_64-apple-darwin10.7.3
Thread model: posix
with -std=c++0x -U__STRICT_ANSI__ -stdlib=libc++

Thanks Howard, you guessed right.

This is my testit result (summary):

****************************************************
Results for /Users/jonkalb/Documents/development/developement/libcxx/test:
using Apple clang version 2.0 (tags/Apple/clang-138) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
with -std=c++0x -stdlib=libc++
----------------------------------------------------
sections without tests : 1
sections with failures : 153
sections without failures: 910
                     + ----
total number of sections : 1064
----------------------------------------------------
number of tests failed : 1221
number of tests passed : 3019
                     + ----
total number of tests : 4240
****************************************************

Is this what I should expect?

I would've expected significantly fewer test failures for clang -std=c++0x
-stdlib=libc++:

****************************************************
Results for /test:
using Apple clang version 2.0 (trunk 125236) (based on LLVM 2.9svn)
Target: x86_64-apple-darwin10
Thread model: posix
with -std=c++0x -stdlib=libc++ -arch x86_64 -U__STRICT_ANSI__ -I../include
/usr/lib/libc++.dylib
----------------------------------------------------
sections without tests : 1
sections with failures : 74
sections without failures: 989
                      + ----
total number of sections : 1064
----------------------------------------------------
number of tests failed : 215
number of tests passed : 4023
                      + ----
total number of tests : 4238
****************************************************

However it has been a couple of months since I actually ran the full test
suite (been busy elsewhere). Did you get libc++abi.dylib from here:

http://home.roadrunner.com/~hinnant/libcppabi.zip

?

http://libcxx.llvm.org/ says:

To build on Mac OS X 10.6, you need a helper library and header found here.
cp cxxabi.h to /usr/include, and cp libc++abi.dylib to /usr/lib.

This library implements things like exception handling. Lack of this library
might explain your failure rate.

If that isn't it, email me privately your entire results and I'll take a look.

Howard

I noticed this difference in our reports:

using Apple clang version 2.0 (tags/Apple/clang-138) (based on LLVM 2.9svn)

using Apple clang version 2.0 (trunk 125236) (based on LLVM 2.9svn)

I think I was getting the clang++ in /usr/lib/ instead of in
/Users/jonkalb/Documents/development/developement/build/Debug+Asserts/bin/

Could that be the issue?

Could be, I was wondering the same thing. I get my clang from an internal daily build instead of from a release.

I've changed my PATH so I now get:

Jon-Kalbs-MacBook-Pro:test jonkalb$ which clang++
/Users/jonkalb/Documents/development/developement/build/Debug+Asserts/bin/cl
ang++

and I'm running testit again. I will send the entire result to you off-list
if it isn't closer to your result.

If it is the difference in clang's, turning off -std=c++0x could actually help as far as passing tests goes. The test suite is looking for that flag and tries to test more stuff when it sees it.

Howard

Ah, yes good point. Yes it is on purpose that the test script doesn't automatically include this flag. I keep "scripts" around so that I can easily try different options:

export OPTIONS="-stdlib=libc++ -arch i386"
export OPTIONS="-stdlib=libc++ -arch x86_64"
export OPTIONS="-std=c++0x -stdlib=libc++ -arch i386 -U__STRICT_ANSI__"
export OPTIONS="-std=c++0x -stdlib=libc++ -arch x86_64 -U__STRICT_ANSI__"

The need for -U__STRICT_ANSI__ should be considered a temporary workaround. I had forgotten about needing it, thanks for the reminder. I'll bet that is what Jon is seeing.

Howard

I tried it with:

    export OPTIONS="-std=c++0x -stdlib=libc++ -U__STRICT_ANSI__"

(I didn't know what architecture to specify.)

And my results are much closer to yours.