c++ - 使用 ELLCC 从 OS X 交叉编译到 ARM

标签 c++ cross-compiling bare-metal ellcc

我正在尝试将 C++(14) 项目从 OS X 交叉编译到 ARM,以便在 Cortex-M4 芯片上运行。 ELLCC project似乎它可以用于此,所以这就是我所做的:

  1. 设置一个简单的测试文件(main.cpp)如下:

    #include <cstddef>
    
    int main() { }
    
  2. http://ellcc.org/releases 下载最新版本的 ELLCC for OS X .下载需要一段时间,但完成后我解压生成的 tarball,我的沙箱如下所示:

    sandbox/
        main.cpp
        ellcc/
            bin/
            examples/
            libecc/
    
  3. 使用 ecc++到(尝试)交叉编译:

    ./ellcc/bin/ecc++ -target arm-none-eabi main.cpp
    

不幸的是,ecc++无法找到 cstddef header :

ldionne in ~/Desktop/ellcc-tests % ./ellcc/bin/ecc++ -v -target arm-none-eabi main.cpp
ecc 0.1.17 based on clang version 3.8.0 (trunk) (based on LLVM 3.8.0svn)
Target: arm-none--eabi
Thread model: posix
InstalledDir: /Users/ldionne/Desktop/ellcc-tests/./ellcc/bin
 "/Users/ldionne/Desktop/ellcc-tests/ellcc/bin/ecc" -cc1 -triple armv4t-none--eabi -emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu arm7tdmi -target-feature +soft-float-abi -target-feature +strict-align -target-abi aapcs -mfloat-abi soft -target-linker-version 253.3.3 -v -dwarf-column-info -resource-dir /Users/ldionne/Desktop/ellcc-tests/ellcc/bin/../libecc -fdeprecated-macro -fdebug-compilation-dir /Users/ldionne/Desktop/ellcc-tests -ferror-limit 19 -fmessage-length 181 -fallow-half-arguments-and-returns -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/hs/9ydnxpjd3plbjqsz34p9cxz00000gn/T/main-d365df.o -x c++ main.cpp
clang -cc1 version 3.8.0 based upon LLVM 3.8.0svn default target x86_64-apple-darwin14.5.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Users/ldionne/Desktop/ellcc-tests/ellcc/bin/../libecc/include
 /usr/include
End of search list.
main.cpp:1:10: fatal error: 'cstddef' file not found
#include <cstddef>
         ^
1 error generated.

第一个问题:我错过了什么?这不应该开箱即用吗?

为了解决缺少 header 的问题,我手动调整了 header 通过添加 -isystem ellcc/libecc/include/c++ 编译器的搜索路径. ecc++现在找到 <cstddef> , 但找不到 bits/alltypes.h :

ldionne in ~/Desktop/ellcc-tests % ./ellcc/bin/ecc++ -v -target arm-none-eabi -isystem ${PWD}/ellcc/libecc/include/c++ main.cpp
[snip]
 "/Users/ldionne/Desktop/ellcc-tests/ellcc/bin/ecc" -cc1 -triple armv4t-none--eabi -emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu arm7tdmi -target-feature +soft-float-abi -target-feature +strict-align -target-abi aapcs -mfloat-abi soft -target-linker-version 253.3.3 -v -dwarf-column-info -resource-dir /Users/ldionne/Desktop/ellcc-tests/ellcc/bin/../libecc -isystem /Users/ldionne/Desktop/ellcc-tests/ellcc/libecc/include/c++ -fdeprecated-macro -fdebug-compilation-dir /Users/ldionne/Desktop/ellcc-tests -ferror-limit 19 -fmessage-length 181 -fallow-half-arguments-and-returns -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/hs/9ydnxpjd3plbjqsz34p9cxz00000gn/T/main-9cd9a7.o -x c++ main.cpp
[snip]
#include <...> search starts here:
 /Users/ldionne/Desktop/ellcc-tests/ellcc/libecc/include/c++
 /usr/local/include
 /Users/ldionne/Desktop/ellcc-tests/ellcc/bin/../libecc/include
 /usr/include
End of search list.
In file included from main.cpp:1:
In file included from /Users/ldionne/Desktop/ellcc-tests/ellcc/libecc/include/c++/cstddef:43:
/Users/ldionne/Desktop/ellcc-tests/ellcc/bin/../libecc/include/stddef.h:17:10: fatal error: 'bits/alltypes.h' file not found
#include <bits/alltypes.h>
         ^
1 error generated.

不死心,我再次手动调整header搜索路径,添加 -isystem ellcc/libecc/include/arm .但是现在我收到一个链接错误:

./ellcc/bin/ecc++ -v -target arm-none-eabi -isystem ${PWD}/ellcc/libecc/include/c++ -isystem ${PWD}/ellcc/libecc/include/arm main.cpp
[snip]
/usr/local/Cellar/gcc-arm-none-eabi-49/20150609/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2: error: ld returned 1 exit status
ecc: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)

输出很长,所以我在这里只包含了相关的部分。完整输出为 here .

第二个问题:为什么链接不上?

请注意,我有 arm-none-eabi-gcc已经安装,我相信这就是为什么 ecc++使用它来链接而不是 ELLCC 本身提供的链接器。 我不能使用 arm-none-eabi-gcc作为前端,因为它对 C++14 的支持有问题,我正在做一些严肃的元编程。

感谢您的帮助。

最佳答案

ELLCC被设计成一个交叉编译工具链。最终目标是允许从任何主机到多个目标环境的交叉编译。目前支持交叉编译到 Linux 和 Windows,对裸机系统的支持有限。

一般来说,ellcc/libecc/config中的其中一个配置是用来告诉编译器去哪里找头文件和库的。 ellcc/libecc/config 中的每个文件都是一个文本文件,如果它作为 ecc(++) -target 选项的参数被提及,则会被读取。如果您查看这些文件,您将看到它们如何设置包含路径等。thumb-linux-engeabi 目标将使用 cortex-m3 (thumb) 指令集编译 linux 应用程序。

ELLCC 有针对 Linux 和 Windows 目标的预编译库,并且(非常)有限地支持像 cortex-m4 这样的裸机目标。目前较大的 ARM 芯片(A8、A9 等)拥有最多的裸机支持。例如转到 ellcc/examples/elk type

[~/ellcc/examples/elk] Richards-Mac-mini% make arm-elk-engeabi
cat: config: No such file or directory
rm -f *.o elk elk.bin elk.log elkconfig.ld
Preprocessing elkconfig.cfg
Compiling main.c
Compiling test_commands.c
Linking elk
[~/ellcc/examples/elk] Richards-Mac-mini%

这将为 A8 构建一个可执行文件。您可以通过以下方式运行它:

[~/ellcc/examples/elk] Richards-Mac-mini% make run
Running elk
enter 'control-A x' to exit QEMU
elk started. Type "help" for a list of commands.
fragcnt = 1 size = 42 tx = 4608
got 'hello world
'
Try the command 'inetif'
elk % 

这是在 QEMU 下以系统仿真模式运行的,没有操作系统。它使用适用于 ARM Linux 的普通 C 和 C++ 标准库,但模拟 Linux 系统调用而不是让 Linux 执行。

我最终希望 cortex-m4 具有类似的功能,但我还没有(日常工作、家庭等的干扰)我已经做了一些初步工作,例如请参阅我关于 compiling for the cortex-m3 的帖子.

我知道这并不能真正回答您的问题,但我希望它能让 ELLCC 的工作原理更加清晰。

关于c++ - 使用 ELLCC 从 OS X 交叉编译到 ARM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33443351/

相关文章:

c++ - C# 到 c++/cli 到 unamanged c++ ref

c# - 从 C# (Windows) 调用 C 函数 (Linux)

linux - u-boot中的fatloat地址限制

c - 进入函数作用域但不在函数调用时指针参数为 NULL

android - 使用 jni 包装 C++ 库

c++ - 如何强制 approxPolyDP() 只返回最好的 4 个角? - Opencv 2.4.2

c++ - ReadFile lpBuffer 参数

android - V8 在 mac 上为 android 构建

c++ - 用arm-linux-g++编译opencv失败(交叉编译)

c - 使用中断处理程序作为事件监听器有什么问题