0
votes

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;
}

cross settings : arm-none-eabi-

path : /usr/lib/arm-none-eabi

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 ?

1
I vaguely remember something about not linking to the standard library or runtime library, where _exit is implemented. ` - Surt

1 Answers

2
votes

These functions are generally part of libgloss for embedded targets.

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.

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.