Linking libc++ to CMake project on Linux

后端 未结 2 1687
心在旅途
心在旅途 2021-02-13 10:54

I want to use libc++ together with clang on Arch Linux in CMake project. I installed libc++ and added following lines to CMakeLists.txt as said on LLVM site in Linux section of

相关标签:
2条回答
  • 2021-02-13 11:48

    Don't forget to set the compiler to clang++:

    set(CMAKE_CXX_COMPILER "clang++")
    

    Also, purge the cmake generated files (delete the folder CMakeFiles and CMakeCache.txt).

    Depending on your system, it might also help to set

    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
    
    0 讨论(0)
  • 2021-02-13 11:51

    The "proper" way to do this in CMake at the moment, until a specific base feature is added to switch standard libraries that is, is to use a toolchain file.

    In that toolchain file you specify the compiler etc similarly to the other answers here.

    BUT what's great about toolchains is they can be swapped out quickly either on the commandline (using -DCMAKE_TOOLCHAIN_FILE=path/to/file) OR in VSCode with CMakeTools extension installed, and probably other editors too.

    But having to hand code your own toolchain files is yet another obscure chore! No fun!

    Luckily, I stumbled upon this github that maintains a suite of them so you don't have to write them from scratch! Should be a lot less likely to get them wrong.

    https://github.com/ruslo/polly

    0 讨论(0)
提交回复
热议问题