简体   繁体   中英

Compilation errors with M1 MacBook Pro and cmake

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM