代码之家  ›  专栏  ›  技术社区  ›  Abhiroop Sarkar

Mac OS Mojave 10.14.5中的交叉编译

  •  0
  • Abhiroop Sarkar  · 技术社区  · 6 年前

    我试图交叉编译以下简单代码

    #include <stdio.h>
    #include <stdlib.h>
    int main() {
      int i;
      for (i = 0; i < 100; i++) {
        printf("Hello World %d!\n", i);
      }
      do {
        i++;
      } while (1);
    }
    

    到 nRF52840Dk 带有Arm Cortex-M4处理器的电路板。我的主机是Macbook Pro 15'',带有MacOS Mojave 10.14.5操作系统。我希望从裸机(没有任何操作系统)开始运行这个程序。

    当我运行以下命令时:

    clang --target=armv7-none-gnueabi foo.c 我明白了 foo.c:1:10: fatal error: 'stdio.h' file not found .

    现在我环顾四周,发现这个问题可能是由于 /usr/include 在较新的OSX变体中。

    我尝试了以下解决方案,但没有取得任何进展:

    1. xcode-select --install

    已经做了。我已经安装了xcode命令行工具。

    1. 跑 open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg 然后继续安装

    我猜这可能是个错误。当我运行这个程序时,我遇到了安装程序,同意了许可证,但是我收到了这个警告 Installing this package may damage your system, and the installation may fail. To stop the program and the installation, click “Cancel Installation”. 无论如何,当我继续安装时,每次都会失败。这是否与Mac禁止运行32位应用程序有关?那么,人们如何在较新的Mac电脑上交叉编译ARM板呢?

    1. 设定 CPATH 环境变量 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include

    也尝试过这样做,但这导致了警告和错误的激增。虽然看起来 stdio.h 已找到,但会引发以下错误:

    error: Unsupported architecture
    #error Unsupported architecture
     ^
    

    以及一系列其他错误。

    因此,我不确定如何进一步进行。有人能告诉我这件事吗?

    0 回复  |  直到 6 年前