Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 views
in Technique[技术] by (71.8m points)

linux - Cmake error setting compiler

For some reason, CMake's C and C++ compilers are set by default to /usr/bin/qcc. I've followed this post and tried the command

cmake -D CMAKE_C_COMPILER=/usr/bin/gcc -D CMAKE_CXX_COMPILER=/usr/bin/g++

but I get the error

CMake Error: The source directory [current directory]/CMAKE_CXX_COMPILER=/usr/bin/g++" does not exist.

Why is CMake interpreting my commands as a directory, and what is the correct way to set CMake's compilers?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You've got the right idea, however the command line you want is:

cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ <path_to_source>

The differences are subtle. There should be no space between the -D and the variable being set, which is why CMake is interpreting your variable assignment as a directory. Also CMake uses CXX for C++ specific variables, which keeps it consistent with Make.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...