[llvm-dev] How to use mainline clang/llvm with CMake

Rakur Moski via llvm-dev llvm-dev at lists.llvm.org
Thu Nov 5 10:00:57 PST 2020


Dear all, I am not sure whether this is a right place to ask basic questions about usage of CLang/LLVM, but also not sure if there is any other mailing list for such.
Kindly point me to such a list in such case.

I had built mainline CLang/LLVM on OSX and tried to use it with CMake. I had override following variables in CMake:

CMAKE_CXX_COMPILER=${LLVM_INSTALL_PATH}/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang++
CMAKE_CXX_STANDARD_LIBRARIES=${LLVM_INSTALL_PATH}/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib
CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES=${LLVM_INSTALL_PATH}/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/include/c++/v1

Though the compilation works, the link stage fails, as I couldn't set the path to newly built LLVM libcxx/libcxxabi.

Could some one please tell what is the correct way to use mainline LLVM in CMake?

Thanks.
Rakur.

PS:
Complete verbose compile logs are available at https://pastebin.com/p3U2EQ1h
Im adding excerpt of compile/link commands and output logs below in this mail too.

It produces the following compilation command:
/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang++ -isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/include/c++/v1 -g -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -std=c++17 -o CMakeFiles/seq_vector.dir/seq_vector.cpp.o -c /Users/user/workspace/github/clang_build/manual/llvm-project/example/seq_vector.cpp

Verbose compile command:
"/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang-12" -cc1 -triple x86_64-apple-macosx10.15.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name seq_vector.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -target-sdk-version=10.15.6 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 609 -v -resource-dir /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/clang/12.0.0 -isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/include/c++/v1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -stdlib=libc++ -internal-isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/local/include -internal-isystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /Users/user/workspace/github/clang_build/manual/llvm-project/example/_build/cmake/Debug -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -o CMakeFiles/seq_vector.dir/seq_vector.cpp.o -x c++ /Users/user/workspace/github/clang_build/manual/llvm-project/example/seq_vector.cpp

But unfortunately, the link stage fails:
/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/bin/clang++ -g -v -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/seq_vector.dir/seq_vector.cpp.o -o seq_vector /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib

Verbose link command:
"/usr/bin/ld" -demangle -lto_library /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 10.15.0 10.15.6 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o seq_vector -search_paths_first -headerpad_max_install_names CMakeFiles/seq_vector.dir/seq_vector.cpp.o /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib -lc++ -lSystem /Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a

Error:
ld: can't map file, errno=22 file '/Users/user/workspace/github/clang_build/manual/llvm-project/_install/Toolchains/LLVM12.0.0git.xctoolchain/usr/lib' for architecture x86_64

-----
I had built Clang with following command:

cmake \
-H./llvm-project/llvm \
-B./llvm-project/_build \
-DCMAKE_INSTALL_PREFIX=./llvm-project/_install \
-G "Ninja" \
-DCMAKE_BUILD_TYPE=Release \
\
-DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;clang-tools-extra;libunwind;lld;pstl;" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_OSX_ARCHITECTURES="x86_64" \
-DLLVM_CREATE_XCODE_TOOLCHAIN=ON \
-DDEFAULT_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201105/494d1f59/attachment.html>


More information about the llvm-dev mailing list