Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify custom libc++

Tags:

c++

clang

libc++

I have built libc++ and want to use it when compiling my program ? so I have something like

clang++ -stdlib=~/libc++/libc++.so main.cpp

but this does not work. How can use my custom built libc++ when building the application?

like image 318
unresolved_external Avatar asked Aug 14 '18 11:08

unresolved_external


1 Answers

This information comes from llvm documentation about libcxx.

If you want to use a custom libc++ with clang you have to specify argument like this :

$ clang++ -std=c++11 -stdlib=libc++ -nostdinc++ -I<path_to_libcxx>/include/c++/v1 -L<path_to_libcxx>/lib -Wl,-rpath,<path_to_libcxx>/lib main.cpp ${end_of_compile_line...}

Alternatively, you can put the path of your library in LD_LIBRARY_PATH (assuming you are under Linux) :

export LD_LIBRARY_PATH=<libcxx-install-prefix>/lib:$LD_LIBRARY_PATH

and compile using simply these options :

$ clang++ -stdlib=libc++ -nostdinc++ -I<path_to_libcxx>/include/c++/v1 -L<path_to_libcxx>/lib main.cpp -o ${end_of_compile_line...}

like image 162
Clonk Avatar answered Oct 14 '22 06:10

Clonk