arm 交叉编译器链接失败

Linking fail for arm cross compiler

我对交叉编译了解不多。我在 linux 机器上使用 eclipse 交叉编译 armv7-a Hellow world 示例。

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

交叉设置:arm-none-eabi-

路径:/usr/lib/arm-none-eabi

交叉 g++ 编译器:g++ -c -fmessage-length=0 -mcpu=cortex-m3 -march=armv7-a

我收到以下链接器错误:

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.

我该如何解决这个问题?

这些函数通常是嵌入式目标的 libgloss 的一部分。

如果您不想提供这些函数的您自己的版本,您可以使用 --specs=nosys.specs。通过使用此规范(您可以阅读它,它是一个文本文件),您将告诉编译器针对包含这些函数的默认版本的 nosys libgloss 更改 link 规范和 link。

请注意,您需要 link 和 --specs=nosys.specs -mthumb -mcpu=cortex-m3 -march=armv7-m 或至少使用 mcpu 选项,否则您将对 __sync_synchronize.

有未定义的引用