在Mac上CMake失败

时间:2018-11-28 20:46:31

标签: c++ macos cmake

我正在运行一个C ++程序来测试我的C ++项目中的代码。我已经使用Eclipse成功运行了它。但是,当我尝试使用CMake进行构建(用于自动测试)时,遇到以下问题: cmake命令可以毫无问题地解决,但是当我运行make时,它会失败,并出现以下三种类别的错误:

In file included from /Users/douglas/Desktop/automatedTesting/src/main.cpp:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:169:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:641:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cstring:61:
In file included from /Users/douglas/Desktop/automatedTesting/src/string.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/sstream:174:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:139:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/streambuf:139:5: error: 
unknown type name 'locale'

与“语言环境”一样,“ streamsize”也会出现相同的问题

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/streambuf:155:41: error: 
  incomplete type 'std::__1::ios_base' named in nested name specifier

最后:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:98:24: note: 
  forward declaration of 'std::__1::ios_base'

这些错误会重复多次,直到总共生成20个错误为止,此时将给出以下最终输出:

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [CMakeFiles/makeTest.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/makeTest.dir/all] Error 2
make: *** [all] Error 2

我的CMakeLists.txt如下:

cmake_minimum_required (VERSION 2.6)
project(makeTest)

set (makeTest_VERSION_MAJOR 1)
set (makeTest_VERSION_MINOR 0)

add_executable(makeTest src/main.cpp serial-messenger/forTest.cpp src/String.cpp src/parson.c)
target_include_directories(makeTest PRIVATE src)
target_include_directories(makeTest PRIVATE serial-messenger)

环境详细信息:

OS:Mac OS High Sierra版本10.13.4

CMake:3.13.0

CLANG:Apple LLVM版本9.1.0(clang-902.0.39.2)

已安装XCode

我确定在为CMake设置环境时一定犯了一些错误,但我不知道它可能是什么。

编辑:由于Mac不区分大小写,因此我将String.h文件误认为是string.h,从而导致了问题。

编辑2:问题确实是由于Mac不区分大小写。在区分大小写的操作系统(如Linux)上运行它可以解决该问题。

1 个答案:

答案 0 :(得分:1)

切勿为具有 custom 功能的标题提供标准名称

仅更改一个案例(从低到高,反之亦然)也不是一个好主意。


根据错误消息中的包含链,系统头文件文件

.../usr/include/c++/v1/cstring

实际上包括一个自定义一个

.../automatedTesting/src/string.h

这是因为您给自定义标头指定了标准名称string.h。 (好吧,文件的实际名称是String.h,但是MacOS使用的是不区分大小写文件系统)。这是一个真正的问题:系统标头希望获得包含此类内容的一些标准定义,但自定义标头不提供这些定义。

将您的自定义标头重命名为非标准名称(例如mystring.h),并相应地调整#include指令。