1

我正在使用带有 CMake (2.8.7) 和 gcc 4.6.3 的 Qt creator 2.5,最近我遇到了这个奇怪的错误:

:-1: 错误:[CMakeFiles/yahtzee.dir/gamecontroller.cpp.o] 错误 1 ​​找不到文件

我能做些什么呢?CMake 没有生成这个gamecontroller.cpp.o

这是我的CMakeLists.txt文件

project(cpp_workshop)
cmake_minimum_required(VERSION 2.6)

# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX)
    message(STATUS "GCC detected, adding compile flags")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra -Werror")
else()
    message(STATUS "GCC not detected, probably running Windows")
endif(CMAKE_COMPILER_IS_GNUCXX)


#add_definitions("-Wall -Werror")
ADD_DEFINITIONS("-Wno-unused-parameter")

add_executable(yahtzee #name of the executable
gamecontroller.h gamecontroller.cpp
player.h player.cpp
game.h game.cpp
dice.h dice.cpp
strategy.cpp strategy.h
istrategy.h
game_rules.h
main singleton 
)

顺便提一下,所有这些文件都位于目录中,这是 CMake 创建的“构建”目录:

CMakeCache.txt  CMakeFiles  cmake_install.cmake  cpp_workshop.cbp  Makefile

和上面的CMakeFiles目录

CMakeCCompiler.cmake               CMakeDirectoryInformation.cmake  CompilerIdCXX   TargetDirectories.txt
cmake.check_cache                  CMakeOutput.log                  Makefile2       yahtzee.dir
CMakeCXXCompiler.cmake             CMakeSystem.cmake                Makefile.cmake
CMakeDetermineCompilerABI_C.bin    CMakeTmp                         Progress
CMakeDetermineCompilerABI_CXX.bin  CompilerIdC                      progress.marks
4

1 回答 1

1

好的,问题在于Cmake传递给 gcc 的参数

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

我把它改成了

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

现在它可以工作了。令人惊讶的是,C++11 还不能与 gcc 一起使用?

于 2012-07-19T08:27:09.923 回答