I am unable to compile C code on neither MacOS Catalina nor Big Sur. I see the header files present in /usr/include/
, but I get errors from my C compiler.
Current error messages I get from the compiler are:
- For "#include <time.h>" => error: cannot open source file "time.h"
- For "#include <stdint.h>" => error: cannot open source file "stdint.h"
What I've tried:
- I tried
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
and it says "upgrade successful", but does not resolve any errors. - I tried uninstalling and reinstalling XCode (Version 10.1)
- I tried downloading the .pkg file you mentioned (because I was missing it) but was told my macOS version was too new
- The files I need are stored in
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
, so we added a new CPATH and PATH variable (separately) for that path to ~/.bash_profile and /etc/paths - I tried to provide
#include
statements with explicit paths to those files, which quickly spiraled out of control - I tried to move all of the required files from the above directory to my project folder and changing the paths appropriately in the code
- I tried to run sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
- The files should also be stored in Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include, so I tried doing the above steps with this path as well
Any advice would be helpful. Thank you!
To provide more clarity based on a comment from Joshua below, these are the steps I followed to set up the 32-bit ARM cross-compiler:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
-
brew install gmp brew install mpfr brew install libmpc
Downloaded "binutils-2.36.tar.xz" from here
Outside of the binutils directory, created a directory called "build32"
-
../binutils-2.36/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers make -j4 all sudo make install
Downloaded "gcc-arm-src-snapshot-10.2-2020.11.tar.xz" from here
Inside the main directory, created a subdirectory called "build32"
-
../gcc-arm-src-snapshot-10.2-2020.11/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers make -j4 all-gcc sudo make install-gcc