0

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:

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:

  1. sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

  2.  brew install gmp
     brew install mpfr
     brew install libmpc
    
  3. Downloaded "binutils-2.36.tar.xz" from here

  4. Outside of the binutils directory, created a directory called "build32"

  5.  ../binutils-2.36/configure --target=arm-none-eabi --disable-nls --enable-languages=c --without-headers
     make -j4 all
     sudo make install
    
  6. Downloaded "gcc-arm-src-snapshot-10.2-2020.11.tar.xz" from here

  7. Inside the main directory, created a subdirectory called "build32"

  8.  ../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
    
Trippzee
  • 1
  • 1
  • 2
    Code? Error message? – SuperStormer Feb 25 '21 at 18:09
  • Sure, I'll add some. – Trippzee Feb 25 '21 at 18:10
  • How do you compile? – alex01011 Feb 25 '21 at 18:13
  • With ARM 32-bit compiler: "make arm-none-eabi-gcc -Wall -O2 -nostdlib -nostartfiles -ffreestanding -c SDCard.c -o SDCard.o In file included from SDCard.c:5: SDCard.h:3:10: fatal error: time.h: No such file or directory 3 | #include | ^~~~~~~~ compilation terminated." – Trippzee Feb 25 '21 at 18:17
  • You see the headers in `/usr/include`? Congratulations — I've not yet seen them there. Have you checked that there is any content when you run `wc /usr/include/time.h`? I'd not be surprised to find it is a broken symlink. You can see some information in the question [Can't compile a C program on a Mac after upgrading to Catalina 10.15](https://stackoverflow.com/questions/58278260/cant-compile-a-c-program-on-a-mac-after-upgrading-to-catalina-10-15) and its answers. I don't have a complete solution. – Jonathan Leffler Feb 25 '21 at 18:18
  • Thanks Jonathan. "wc /usr/include/time.h" returns "198 971 7669 /usr/include/time.h". And I have been referencing various solutions in the link you shared. – Trippzee Feb 25 '21 at 18:21
  • 1
    "`arm-none-eabi-gcc`": Your cross-compilation build chain is broken. This isn't going to use the system copies in `/usr/include` but the copies from the target archiecture. While `stdint.h` certainly should exist, it's currently missing. – Joshua Feb 25 '21 at 18:34
  • The current version of XCode for Mojave (10.14.6 — a predecessor to Catalina 10.15.x and Big Sur 11.1) is 11.3.1; there are newer versions for both Catalina and Big Sur. Attempting to use Xcode 10.1 on Catalina or Big Sur seems like creating unnecessary hardship for yourself. – Jonathan Leffler Feb 25 '21 at 19:01
  • I upgraded to Big Sur and XCode 12.4. Unsurprisingly, the issue has not been magically fixed. Is there a recommended way of troubleshooting the cross-compilation build chain? – Trippzee Feb 26 '21 at 16:36

1 Answers1

0

I ended up switching to a Windows Subsystem for Linux setup on another machine for what I was working on. Another option is to set up a VM on the Mac. I could not figure out another solution for getting it to "just work" on the Mac. Thanks to everyone for the suggestions!

For those looking to pivot to WSL, follow this setup guide.

For those looking to go the VM workaround route, this is one process that was graciously recommended to me:

"1. Install Virtualbox from https://www.virtualbox.org/

  1. Install Vagrant from https://www.vagrantup.com/

  2. Download the prebuilt ARM gcc cross compiler from the link above in my question.

  3. Move the download file into the project directory and run the following command to extract it:

    tar -xvf gcc-arm-10.2-2020.11-x86_64-arm-none-eabi.tar.xz

  4. Download this Vagrantfile (fyi 'this' triggers a download of said file) and move it to the project directory as well. This file tells vagrant how to setup the VM. It will mount the project directory as well as the SD card. On line 41 of this file it tells vagrant where the SD card is located so change the first path on this line to where your SD card is located. Additionally, because the project directory is mounted, you can still edit the project files locally on your machine instead of having to use what's on the VM if you use this solution.

  5. After all that, you should be ready to create/start the VM using the command vagrant up. To log into the VM, vagrant ssh after the vagrant up command finishes. Your project files should be located in the /vagrant directory. You are now all setup to compile the project and if you run make cp it should compile the project and copy it over to the SD card.

  6. To shutdown the VM you can run vagrant halt to shutdown the VM, and to get rid of the VM you can run vagrant destroy. vagrant destroy will not delete any of the files that were shared from your computer to the VM."

Trippzee
  • 1
  • 1