7

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?

5
  • 3
    Have you tried using a absolute path? (~ is not absolute). Also, specify what does not work? Do you have an error message? Commented Aug 14, 2018 at 11:08
  • I've tried with absolute path as well, Clang says: "invalid library in argument -stdlib=~/libc++/libc++.so" Commented Aug 14, 2018 at 11:18
  • Please update your question, do not post it as a comment :) Commented Aug 14, 2018 at 11:37
  • 1
    The -stdlib=~/libc++/libc++.so argument is invalid. Clang accepts -stdlib=libc++, and you have to add the library to your PATH. See this for more details. Commented Aug 14, 2018 at 11:37
  • But I already have the default libc++, will it override it ? Commented Aug 14, 2018 at 12:42

1 Answer 1

6

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.