3

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.

GoldenBadger
  • 143
  • 1
  • 7
  • @BaummitAugen No I think it's [just for C](http://stackoverflow.com/a/11394799/3299106). Either way, I tried changing CC to `/usr/bin/clang++` and it didn't work. – GoldenBadger Aug 06 '15 at 21:11
  • This may only be tangentially related, but you may want to try one of the answers to a similar question I asked and see if they work. http://stackoverflow.com/questions/28728685/force-target-link-libraries-to-use-c-linker – user3288829 Aug 08 '15 at 15:03

1 Answers1

-1

You can specify the cpp compiler to cmake directly

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

Anoop
  • 5,540
  • 7
  • 35
  • 52