M1 MacBook Pro和cmake的编译错误 [英] Compilation errors with M1 MacBook Pro and cmake
问题描述
我刚刚获得了新的M1 MacBook Pro,并且正在尝试编译大学工作所需的代码库.这是我已采取的步骤:
I have just got my new M1 MacBook Pro and am trying to compile a code base required for my university work. Here are the steps I have taken:
- 我将终端设置为始终使用Rosetta打开.
- 使用/bin/bash -c" $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)安装的自制软件
"
- 使用
brew install cmake
安装的cmake - 运行
cmake< source的路径>
(这很好) - 运行
make
(失败)
- I set Terminal to always open using Rosetta.
- Installed homebrew
using /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Installed cmake using
brew install cmake
- Run
cmake <path to source>
(this works fine) - Run
make
(this fails)
这是我得到的错误:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:97:15: fatal error:
'stdlib.h' file not found
#include_next <stdlib.h>
我尝试卸载Xcode和CommandLineTools并将其重新安装无济于事.
I have tried uninstalling and re-installing Xcode and CommandLineTools to no avail.
使用cmake gui应用程序时,出现另一个错误.我将其设置为使用CommandLineTools/SDKs/MacOsX11.0.sdk.
When using the cmake gui app, I get a different error. I have it set to use CommandLineTools/SDKs/MacOsX11.0.sdk.
使用此cmake gui设置生成并配置了生成文件后,运行 make
时,出现此错误:
When running make
after generating and configuring the build files using this cmake gui setup, I get this error:
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/freyamurphy/nori/build/ext_build/src/tbb_p-build/CMakeFiles/CMakeTmp
如果我运行命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc test.c
(简单的hello world程序),则会出现此错误:
If I run the command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc test.c
(Simple hello world program) I get this error:
test.c:1:10: fatal error: 'stdio.h' file not found
#include "stdio.h"
但是使用 cc test.c
一切正常.(这将运行usr/bin/cc).
But using cc test.c
everything works fine. (This runs usr/bin/cc).
在我看来Xcode可能有问题.有没有人有任何类似的问题或可以给我一些建议?非常感谢.
Seems to me there is perhaps an issue with Xcode. Has anyone had any similar issues or could give me some advice? It would be much appreciated.
推荐答案
在安装xcode之后,您是否重新打开了终端?需要设置环境变量 SDKROOT
.
Have you reopen Terminal after xcode installed? It's needed to set the environment variable SDKROOT
.
关闭并再次运行Terminal或在Terminal中打开新标签.
Close and run again Terminal or open a new tab in Terminal.
或在当前终端中运行以下命令
Or run the following command in the current Terminal
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
还要确保选择了正确的xcode工具链
Also be sure the proper xcode toolchain is selected
# list available xcode toolchains
xcode-select -p
# select one of listed above
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
这篇关于M1 MacBook Pro和cmake的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!