【发布时间】: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 时它编译得很好。您知道问题的原因是什么吗?