问题描述
我对交叉编译不太了解.我在linux机器上使用eclipse交叉编译armv7-a Hellow world Example.
I do not know much about cross-comping. I am using eclipse on linux machine to cross compile armv7-a Hellow world Example.
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
交叉设置:arm-none-eabi-
cross settings : arm-none-eabi-
路径:/usr/lib/arm-none-eabi
path : /usr/lib/arm-none-eabi
跨g++编译器:g++ -c -fmessage-length=0 -mcpu=cortex-m3 -march=armv7-a
cross g++ compiler :g++ -c -fmessage-length=0 -mcpu=cortex-m3 -march=armv7-a
我收到以下链接器错误:
I got the following linker error :
13:54:47 **** Incremental Build of configuration Debug for project Hellocpp ****
make all
Building file: ../src/main.cpp
Invoking: Cross G++ Compiler
arm-none-eabi-g++ -O0 -g3 -Wall -c -fmessage-length=0 -mthumb -mcpu=cortex-m3 -march=armv7-a -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp"
../src/main.cpp:1:0: warning: switch -mcpu=cortex-m3 conflicts with -march=armv7-a switch
//============================================================================
Finished building: ../src/main.cpp
Building target: Hellocpp
Invoking: Cross G++ Linker
arm-none-eabi-g++ -o "Hellocpp" ./src/main.o
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libstdc++.a(locale_init.o): In function `(anonymous namespace)::get_locale_mutex()':
/build/libstdc++-arm-none-eabi-yOFevq/libstdc++-arm-none-eabi-10/build/libstdc++/src/c++98/../../../../src/libstdc++-v3/src/c++98/locale_init.cc:66: undefined reference to `__sync_synchronize'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libstdc++.a(locale.o): In function `get_locale_cache_mutex':
/build/libstdc++-arm-none-eabi-yOFevq/libstdc++-arm-none-eabi-10/build/libstdc++/src/c++98/../../../../src/libstdc++-v3/src/c++98/locale.cc:36: undefined reference to `__sync_synchronize'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libstdc++.a(future.o): In function `__future_category_instance':
/build/libstdc++-arm-none-eabi-yOFevq/libstdc++-arm-none-eabi-10/build/libstdc++/src/c++11/../../../../src/libstdc++-v3/src/c++11/future.cc:64: undefined reference to `__sync_synchronize'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-abort.o): In function `abort':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
makefile:45: recipe for target 'Hellocpp' failed
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-fstatr.o): In function `_fstat_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/fstatr.c:62: undefined reference to `_fstat'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-openr.o): In function `_open_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/openr.c:59: undefined reference to `_open'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/sbrkr.c:58: undefined reference to `_sbrk'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_kill_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-signalr.o): In function `_getpid_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/signalr.c:97: undefined reference to `_getpid'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-writer.o): In function `_write_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/writer.c:58: undefined reference to `_write'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-closer.o): In function `_close_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/closer.c:53: undefined reference to `_close'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-isattyr.o): In function `_isatty_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/isattyr.c:58: undefined reference to `_isatty'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-lseekr.o): In function `_lseek_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/lseekr.c:58: undefined reference to `_lseek'
/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/libc.a(lib_a-readr.o): In function `_read_r':
/build/newlib-jo3xW1/newlib-2.4.0.20160527/build/arm-none-eabi/newlib/libc/reent/../../../../../newlib/libc/reent/readr.c:58: undefined reference to `_read'
collect2: error: ld returned 1 exit status
make: *** [Hellocpp] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
我该如何解决这个问题?
How can I solve this ?
推荐答案
这些函数通常是嵌入式目标的 libgloss 的一部分.
These functions are generally part of libgloss for embedded targets.
如果您不想提供这些函数的自己版本,您可以使用--specs=nosys.specs
.通过使用此规范(您可以阅读它,它是一个文本文件),您将告诉编译器更改链接规范并链接到包含这些函数的默认版本的 nosys libgloss.
If you don't want to provide your own versions of these functions, you can use --specs=nosys.specs
. By using this spec ( you can read it, it is a text file), you will tell the compiler to change link spec and link against nosys libgloss which contains default versions of these functions.
请注意,您需要与 --specs=nosys.specs -mthumb -mcpu=cortex-m3 -march=armv7-m
或至少与 mcpu 选项链接,否则您将拥有对 __sync_synchronize
的未定义引用.
Be careful you will need to link with --specs=nosys.specs -mthumb -mcpu=cortex-m3 -march=armv7-m
or at least with the mcpu option otherwise you will have undefined reference to __sync_synchronize
.
这篇关于arm交叉编译器的链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!