【问题标题】:CMake fails on Mac [closed]CMake 在 Mac 上失败 [关闭]
【发布时间】:2018-11-28 20:46:30
【问题描述】:

我正在运行一个 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'

与“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)

环境详情:

操作系统: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 等区分大小写的操作系统上运行它可以解决此问题。

【问题讨论】:

  • 这看起来像是编译错误,而不是 cmake 错误。而且这个项目看起来像一个普通的可执行项目,它似乎没有使用任何测试库。
  • @VTT 当使用 eclipse 而不是 CMake 时它编译得很好。您知道问题的原因是什么吗?

标签: c++ macos cmake


【解决方案1】:

永远不要为具有自定义功能的标题提供标准名称

只改变一个大小写(从小到大,反之亦然)也不是一个好主意。


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

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

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

.../automatedTesting/src/string.h

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

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


【讨论】:

  • 好吧,开枪。这样做的重点是包含一个 String 类,以便 C++ 程序可以测试为 arduino 编写的代码。自动化测试中的实际文件名为 String.h,而不是 string.h,但我猜编译器没有注意到差异。看看我能不能得到它来关注这个案子。感谢您指出这一点!
  • 感谢您的评论。我在答案中添加了一条关于 MacOS 不区分大小写特性的注释。
猜你喜欢
  • 2011-11-13
  • 2013-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
相关资源
最近更新 更多