简体   繁体   English

C 代码在 MacOS Catalina 或 Big Sur 中无法编译

[英]C Code Won't Compile in MacOS Catalina or Big Sur

I am unable to compile C code on neither MacOS Catalina nor Big Sur.我无法在 MacOS Catalina 和 Big Sur 上编译 C 代码。 I see the header files present in /usr/include/ , but I get errors from my C compiler.我看到/usr/include/中存在 header 文件,但我的 C 编译器出现错误。

Current error messages I get from the compiler are:我从编译器得到的当前错误消息是:

  • For "#include <time.h>" => error: cannot open source file "time.h"对于“#include <time.h>”=> 错误:无法打开源文件“time.h”
  • For "#include <stdint.h>" => error: cannot open source file "stdint.h"对于“#include <stdint.h>”=> 错误:无法打开源文件“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:为了根据下面 Joshua 的评论提供更清晰的信息,这些是我设置 32 位 ARM 交叉编译器所遵循的步骤:

  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这里下载“binutils-2.36.tar.xz”

  4. Outside of the binutils directory, created a directory called "build32"在 binutils 目录之外,创建了一个名为“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这里下载“gcc-arm-src-snapshot-10.2-2020.11.tar.xz”

  7. Inside the main directory, created a subdirectory called "build32"在主目录中,创建了一个名为“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

I ended up switching to a Windows Subsystem for Linux setup on another machine for what I was working on.我最终切换到 Windows 子系统,用于在另一台机器上设置 Linux,以完成我正在处理的工作。 Another option is to set up a VM on the Mac.另一种选择是在 Mac 上设置 VM。 I could not figure out another solution for getting it to "just work" on the Mac.我想不出另一种解决方案让它在 Mac 上“正常工作”。 Thanks to everyone for the suggestions!感谢大家的建议!

For those looking to pivot to WSL, follow this setup guide.对于那些希望将 pivot 转换为 WSL 的用户,请遵循设置指南。

For those looking to go the VM workaround route, this is one process that was graciously recommended to me:对于那些寻找 go 虚拟机解决方法路线的人来说,这是一个被亲切地推荐给我的过程:

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

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

  2. Download the prebuilt ARM gcc cross compiler from the link above in my question.从我的问题中的上述链接下载预构建的 ARM gcc 交叉编译器。

  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 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.下载这个Vagrantfile (仅供参考'this'触发下载所述文件)并将其移动到项目目录。 This file tells vagrant how to setup the VM.此文件告诉 vagrant 如何设置 VM。 It will mount the project directory as well as the SD card.它将挂载项目目录以及 SD 卡。 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.在此文件的第 41 行,它告诉 vagrant SD 卡所在的位置,因此将此行的第一个路径更改为 SD 卡所在的位置。 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.此外,由于项目目录已挂载,因此如果使用此解决方案,您仍然可以在计算机上本地编辑项目文件,而不必使用 VM 上的内容。

  5. After all that, you should be ready to create/start the VM using the command vagrant up.毕竟,您应该准备好使用命令 vagrant up 创建/启动 VM。 To log into the VM, vagrant ssh after the vagrant up command finishes.在 vagrant up 命令完成后,要登录到 VM,vagrant ssh。 Your project files should be located in the /vagrant directory.您的项目文件应位于 /vagrant 目录中。 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.您现在已准备好编译项目,如果您运行 make cp 它应该编译项目并将其复制到 SD 卡。

  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.要关闭 VM,您可以运行 vagrant halt 来关闭 VM,要摆脱 VM,您可以运行 vagrant destroy。 vagrant destroy will not delete any of the files that were shared from your computer to the VM." vagrant destroy 不会删除从您的计算机共享到 VM 的任何文件。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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