简体   繁体   中英

CMake using clang instead of clang++

I'm trying to get CMake and Clang to work with my program. I have set the environment variables CC and CXX as such:

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

But when I run cmake . and make I get a linker error because it is using /usr/bin/clang and not /usr/bin/clang++ and so cannot see the C++ standard library. After running make VERBOSE=1 , this is what I get:

/usr/bin/clang   -std=c++11 -Wall -O3   CMakeFiles/Saruman.dir/Board.cpp.o
CMakeFiles/Saruman.dir/CaptureList.cpp.o CMakeFiles/Saruman.dir/Evaluation.cpp.o
CMakeFiles/Saruman.dir/main.cpp.o CMakeFiles/Saruman.dir/MoveList.cpp.o
CMakeFiles/Saruman.dir/Search.cpp.o CMakeFiles/Saruman.dir/TranspositionTables.cpp.o 
CMakeFiles/Saruman.dir/UCI.cpp.o  -o Saruman -rdynamic -lpthread 

CMakeFiles/Saruman.dir/Board.cpp.o: In function Board::Board(std::string)':
/home/terry/code/chess/engine/Source/Board.cpp:(.text+0x100): undefined reference to
`std::string::compare(char const*) const'

And it is clearly calling /usr/bin/clang instead of /usr/bin/clang++ . When I manually run

clang++ -std=c++11 -Wall -O3 ...

it compiles perfectly.

Any help would be greatly appreciated.

您可以直接将cpp编译器指定为cmake

cmake . -DCMAKE_CXX_COMPILER=/usr/bin/clang++

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM