clang++ doesn't seem to search CMAKE_INSTALL_PREFIX/lib

My apologies for this newbie question. I was unable to discover the answer in the clang and cmake documents.

I have built my own copy of llvm/clang 3.7.0 on FreeBSD 10.1. In the llvm projects directory, I populated compiler-rt, libcxx, and libunwind, also version 3.7.0.

I then built and installed with

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$top -DCMAKE_VERBOSE_MAKEFILE=on -DLLVM_TARGETS_TO_BUILD=host …/$llvm_unpack &&
cmake --build .
cmake --build . --target install

When I try to build using the installed compiler, it is unable to find the libc++ that it just installed:

$top/bin/clang++ -v -o hello hello.cc clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-unknown-freebsd10.1
Thread model: posix
“/usr0/dws/llvm-3.7/top/bin/clang-3.7” -cc1 -triple x86_64-unknown-freebsd10.1 -emit-obj -mrelax-all -disable-free -main-file-name hello.cc -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -resource-dir /usr0/dws/llvm-3.7/top/bin/…/lib/clang/3.7.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /usr0/dws/llvm-3.7 -ferror-limit 19 -fmessage-length 167 -mstackrealign -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/hello-4b055a.o -x c++ hello.cc
clang -cc1 version 3.7.0 based upon LLVM 3.7.0 default target x86_64-unknown-freebsd10.1
#include “…” search starts here:
#include <…> search starts here:
/usr/include/c++/v1
/usr0/dws/llvm-3.7/top/bin/…/lib/clang/3.7.0/include
/usr/include
End of search list.
“/usr/bin/ld” --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o hello /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/hello-4b055a.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/usr/bin/ld: cannot find -lc++
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)

In order to expose this problem, I moved aside the /usr/lib/libc++* files on the system. Prior to that, this compiler was silently using the system’s own libc++ library instead of the one that was built and installed along with the compiler.

I was expecting that the compiler would pay attention to the CMAKE_INSTALL_PREFIX that it was built with.

What’s the proper way (or at least, the expected way) to get clang++ to pay attention to the CMAKE_INSTALL_PREFIX that it was built with?

Regards,
David Sanderson (yelliott@gmail.com)

Hi,

Try: -DLLVM_BUILD_LLVM_DYLIB=ON