cmake:c ++:error:$ {CFLAGS}:没有这样的文件或目录

时间:2017-02-26 19:31:24

标签: cmake environment-variables cflags

我正在尝试关注此cmake tutorial。但是当我第一次调用cmake时,我收到以下错误:

sel

当我在bash中调用cmake -G "Unix Makefiles" .. --debug-trycompile debug trycompile on -- The C compiler identification is GNU 6.3.1 -- The CXX compiler identification is unknown -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- broken CMake Error at /usr/share/cmake-3.7/Modules/CMakeTestCXXCompiler.cmake:44 (message): The C++ compiler "/usr/bin/c++" is not able to compile a simple test program. It fails with the following output: Change Dir: /home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp Run Build Command:"/usr/bin/make" "cmTC_7a86e/fast" /usr/bin/make -f CMakeFiles/cmTC_7a86e.dir/build.make CMakeFiles/cmTC_7a86e.dir/build make[1]: Entering directory '/home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp' Building CXX object CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o /usr/bin/c++ -march=native -O2 -pipe -fstack-protector-strong -o CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o -c /home/user01/code/tests/cmake_tutorial_02/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx Linking CXX executable cmTC_7a86e /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7a86e.dir/link.txt --verbose=1 /usr/bin/c++ ${CFLAGS} CMakeFiles/cmTC_7a86e.dir/testCXXCompiler.cxx.o -o cmTC_7a86e c++: error: ${CFLAGS}: No such file or directory 时,值为:

echo $CFLAGS

但是在执行cmake_link_script时看起来没有定义-march=native -O2 -pipe -fstack-protector-strong 。要验证我已将link.txt中的${CFLAGS}更改为${CFLAGS}并手动调用:

-march=native -O2 -pipe -fstack-protector-strong

有效。

接下来,我尝试将以下行添加到CMakeLists.txt:

/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7a86e.dir/link.txt

没有帮助。

也没有打电话:

set (CFLAGS -O2)

所以我的问题是,如何定义CFLAGS,以便在cmake的命令模式下调用cmake_link_script时定义它?

修改

看起来cmake在“Unix Makefiles”生成器中失败了,甚至没有看到教程中的代码。

CMakeLists.txt看起来像这样:

cmake -DCFLAGS=-O2 -G "Unix Makefiles" ..

EDIT2

我找到了解决方法。 由于某种原因,生成器在CMakeCache.txt中设置project("To Do List") add_executable(toDo main.cc ToDo.cc) 。 但是当使用:

调用生成器时
CMAKE_CXX_FLAGS:STRING='${CFLAGS} '
一切正常。即使“CXX编译器识别未知”消息也消失了。 但是,我仍然想知道为什么发生器在之前失败了?

0 个答案:

没有答案