Compilation errors with M1 MacBook Pro and cmake

不想你离开。 提交于 2021-01-27 07:08:48

问题


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:

  1. I set Terminal to always open using Rosetta.
  2. Installed homebrew using /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Installed cmake using brew install cmake
  4. Run cmake <path to source> (this works fine)
  5. Run make (this fails)

Here is the error I get:

/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>

I have tried uninstalling and re-installing Xcode and CommandLineTools to no avail.

When using the cmake gui app, I get a different error. I have it set to use CommandLineTools/SDKs/MacOsX11.0.sdk.

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

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"

But using cc test.c everything works fine. (This runs usr/bin/cc).

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.


回答1:


Have you reopen Terminal after xcode installed? It's needed to set the environment variable SDKROOT.

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)

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


来源:https://stackoverflow.com/questions/65276102/compilation-errors-with-m1-macbook-pro-and-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!