我正在尝试将 C++(14) 项目从 OS X 交叉编译到 ARM,以便在 Cortex-M4 芯片上运行。ELLCC项目似乎可以用于此目的,所以这就是我所做的:
设置一个简单的测试文件 (
main.cpp
),如下所示:#include <cstddef> int main() { }
从http://ellcc.org/releases下载最新版本的 ELLCC for OS X。下载需要一段时间,但完成后我解压缩生成的 tarball,我的沙箱看起来像:
sandbox/ main.cpp ellcc/ bin/ examples/ libecc/
用于
ecc++
(尝试)交叉编译:./ellcc/bin/ecc++ -target arm-none-eabi main.cpp
不幸的是,ecc++
无法找到cstddef
标题:
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.
第一个问题:我错过了什么?这不应该开箱即用吗?
为了解决缺少头文件的问题,我手动调整编译器的头文件搜索路径,添加-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.
不放弃,我再次通过添加手动调整标题搜索路径
-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)
输出很长,所以我在这里只包括了相关的部分。完整的输出在这里。
第二个问题:为什么不链接?
请注意,我已经arm-none-eabi-gcc
安装了,我相信这就是为什么ecc++
使用它来链接而不是使用 ELLCC 本身提供的链接器。我不能arm-none-eabi-gcc
用作前端,因为它对 C++14 的支持是错误的,而且我正在做一些严肃的元编程。
谢谢你的帮助。