【发布时间】:2015-01-31 02:41:34
【问题描述】:
所以我有以下 CMakeLists.txt 文件来尝试构建我的 main.cpp 文件。
project(shell)
set(extra_flags = -std=c++11 -Werror -Wall -Wextra)
set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))
add_executable(shell main.cpp)
此时,我只是尝试使用 Hello World 程序构建它,以确保一切正常。但是对于我需要编写的程序的其余部分,这些标志是存在的。调用cmake . 的实际过程工作正常,但是当我使用make 时出现以下错误:
[100%] Building CXX object CMakeFiles/shell.dir/main.cpp.o
c++: fatal error: no input files
compilation terminated.
/bin/sh: 1: -o: not found
CMakeFiles/shell.dir/build.make:54: recipe for target 'CMakeFiles/shell.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/shell.dir/main.cpp.o] Error 127
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/shell.dir/all' failed
make[1]: *** [CMakeFiles/shell.dir/all] Error 2
Makefile:72: recipe for target 'all' failed
make: *** [all] Error 2
我是 Ubuntu 和命令行的新手,因此非常感谢任何帮助。
【问题讨论】:
-
您不希望在 set 命令中使用 =。将
set(extra_flags = -std=c++11 -Werror -Wall -Wextra)更改为set(extra_flags -std=c++11 -Werror -Wall -Wextra) -
还将
set(CMAKE_CXX_FLAGS $(CMAKE_CXX_FLAGS) $(extra_flags))更改为set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${extra_flags}) -
感谢您的回复,我已经尝试了这两个更改,但我仍然看到相同的错误,但这次有额外的行
/bin/sh: 1: -Werror: not found/bin/sh: 1: -Wall: not found/bin/sh: 1: -Wextra: not found。如果有帮助,我的 CMakeLists.txt 和 main.cpp 也在同一个目录中。 -
尝试删除 CMakeCache.txt 并使用 cmake 重新配置并重建。
-
也许这会有所帮助:stackoverflow.com/a/21561742/487892