Linking libc++ to CMake project on Linux

末鹿安然 提交于 2020-01-01 08:44:40

问题


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 "Using libc++ in your programs":

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")

I have tried just "++abi" in linker's flags, but it didn't help. I need some help in figuring out what i should write in my CMakeLists.txt.


回答1:


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")


来源:https://stackoverflow.com/questions/27178106/linking-libc-to-cmake-project-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!