macOS(正在构建cmake项目)上的C ++编译器出现问题

时间:2020-01-31 06:36:18

标签: c++ xcode macos

我有一台16英寸的MacBook Pro,具有最新更新(macOS Catalina 10.15.2(19C57)),最新版本的XCode和macOS命令行工具(该工具安装在通常的路径/ Library / Developer / CommandLineTools / )..不确定这是否与我的问题有关,但我的计算机上也安装了最新版本的JetBrains的CLion(无问题运行)。

这是问题所在::尝试使用cmake生成项目时,生成失败,并显示以下错误消息:

In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootDFile.cc:25:
In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootD.hh:28:
In file included from /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 
      'string.h' file not found
#include_next <string.h>
1 error generated.
error: command '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc' failed with exit status 1
make[2]: *** [bindings/python/python_bindings] Error 1
make[1]: *** [bindings/python/CMakeFiles/python_target.dir/all] Error 2
make: *** [all] Error 2

,这可能与我的C ++编译器没有正确的包含文件路径有关。为了弄清楚问题出在哪里,我制作了一个简单的C ++文件,然后尝试对其进行编译。

main.cpp

#include <iostream>

#include <string>
#include <cmath>
#include <vector>

int main()
{
    std::string name = "NAMEX";
    std::cout << name;
}

首先,我尝试使用通常的“ g ++”,但效果很好:

basavyr@Roberts-MacBook-Pro stringTestCLANG % g++ main.cpp 
basavyr@Roberts-MacBook-Pro stringTestCLANG % ./a.out 
NAMEX%                                                                                                                basavyr@Roberts-MacBook-Pro stringTestCLANG %

然后,我尝试使用/Applications/Xcode.app/Contents/Developer/usr/bin/g++ main.cpp,但效果很好。 在我的机器上检查“ g ++”的版本可以得到以下信息:

g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

这很有趣,因为我期望将 default 编译器安装在/usr/bin/中。进入那个“ InstalledDir”文件夹,我发现没有“ g ++”二进制文件,只有“ clang ++”和“ c ++”,所以我试图同时使用它们进行编译,结果发现两个编译器都给出了与那个相同的错误。在我尝试构建的项目中:

basavyr@Roberts-MacBook-Pro stringTestCLANG % /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ main.cpp
In file included from main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:505:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 
      'string.h' file not found
#include_next <string.h>
              ^~~~~~~~~~
1 error generated.
basavyr@Roberts-MacBook-Pro stringTestCLANG %

由于我还安装了命令行工具,因此我尝试同时使用/Library/Developer/CommandLineTools/usr/bin/中的“ g ++”和“ clang ++”进行编译,第一个成功编译,而第二个在编译时抛出了相同的错误。字符串头文件。

basavyr@Roberts-MacBook-Pro stringTestCLANG % /Library/Developer/CommandLineTools/usr/bin/c++ main.cpp
In file included from main.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:505:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string_view:176:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__string:57:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cstring:61:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
#include_next <string.h>
              ^~~~~~~~~~
1 error generated.

因此,我假设当我使用cmake构建该项目时,它正在使用这些编译器之一(来自XCodeDefault.xctoolchain文件夹),并且字符串头有问题。

问题1:如何解决此问题? 第二季度:而且,为什么我的“ g ++”安装目录指向此XCodeDefault.xctoolchain而不是“ / usr / bin /”或“ /Applications/Xcode.app/Contents/Developer/usr/ bin /”。有没有办法在macOS中进行更改?

提前谢谢

0 个答案:

没有答案