I want create a project for the STM32F217IG microcontroller.
So I installed Eclipse and the GNU for ARM embedded GCC cross compiler. I don't think it is the Code Sourcery one. I used it, because it supports floating point and Code Sourcery does not.
Once I did that I tried creating a really small project with only two sources files: test.c and main.c with only the following Code written in both of them:
#include <stdlib.h> #include <stdio.h> int main (void) { printf("Hello, World!"); return 0; } I changed the line command in the project property to replace GCC with arm-none-eabi-gcc and then tried to compile the project.
I did not create any makefile myself; I used the automatic creation in Eclipse.
The building seems to be fine, but when it comes to the linker I got the following errors in the console:
make all 'Building target: test3' 'Invoking: Cross GCC Linker' arm-none-eabi-gcc -o"test3" ./main.o ./test3.o c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): In function `exit': exit.c:(.text.exit+0x2c): undefined reference to `_exit' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r': sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-writer.o): In function `_write_r': writer.c:(.text._write_r+0x20): undefined reference to `_write' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-closer.o): In function `_close_r': closer.c:(.text._close_r+0x18): undefined reference to `_close' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-fstatr.o): In function `_fstat_r': fstatr.c:(.text._fstat_r+0x1c): undefined reference to `_fstat' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-isattyr.o): In function `_isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to `_isatty' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-lseekr.o): In function `_lseek_r': lseekr.c:(.text._lseek_r+0x20): undefined reference to `_lseek' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-readr.o): In function `_read_r': readr.c:(.text._read_r+0x20): undefined reference to `_read' collect2: ld returned 1 exit status make: *** [test3] Erreur 1 I looked on the Internet, and I found that it may be a syscall problem. But I don't know how I add this library to my project on Linux.
Is that really the problem? If yes, how do I fix it? And if not, where is the error coming from?
As someone suggested, I tried "linking" the C runtime library. In Eclipse it seems I have two solutions to do it:
First on the project properties → C/C++ → Build → Settings → Cross linker → libraries. I just add the letter c and then the error does not change, but there is -lc at the end of the command line:
make all 'Building target: test3' 'Invoking: Cross GCC Linker' arm-none-eabi-gcc -o"test3" ./main.o ./test3.o -lc c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): In function `exit': exit.c:(.text.exit+0x2c): undefined reference to `_exit' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-sbrkr.o): In function `_sbrk_r': sbrkr.c:(.text._sbrk_r+0x18): undefined reference to `_sbrk' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-writer.o): In function `_write_r': writer.c:(.text._write_r+0x20): undefined reference to `_write' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-closer.o): In function `_close_r': closer.c:(.text._close_r+0x18): undefined reference to `_close' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-fstatr.o): In function `_fstat_r': fstatr.c:(.text._fstat_r+0x1c): undefined reference to `_fstat' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-isattyr.o): In function `_isatty_r': isattyr.c:(.text._isatty_r+0x18): undefined reference to `_isatty' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-lseekr.o): In function `_lseek_r': lseekr.c:(.text._lseek_r+0x20): undefined reference to `_lseek' c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libc.a(lib_a-readr.o): In function `_read_r': readr.c:(.text._read_r+0x20): undefined reference to `_read' collect2: ld returned 1 exit status make: *** [test3] Erreur 1 But I don't know if it is really means to add the C runtime library.
Second, I added the libc.a library in the project properties → C/C++ general → Path and symbols → Libraries, and here is what I get (completely different):
make all 'Building target: test3' 'Invoking: Cross GCC Linker' arm-none-eabi-gcc -o"test3" ./main.o ./test3.o -l"C:/Program\ Files/GNU\ Tools\ ARM\ Embedded/4.6\ 2012q4/arm-none-eabi/lib/armv7-m/libc.a" c:/program files/gnu tools arm embedded/4.6 2012q4/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: cannot find -lC:/Program\ Files/GNU\ Tools\ ARM\ Embedded/4.6\ 2012q4/arm-none-eabi/lib/armv7-m/libc.a collect2: ld returned 1 exit status make: *** [test3] Erreur 1 Then it still does not work, but is it the good way to search on?
Oh and a very interesting fact:
I got the errors only in debug mode. If I am in release mode everything is okay, and I don't have any errors (except if I add the libc.a then I think this is not the best thing to do). Does that mean the problem is the .elf file creation?
... -l"C:/Program Files/GNU Tools ARM Embedded/4.6 2012q4/arm-none-eabi/lib/armv7-m/libc.a"or... -lC:/Program\ Files/GNU\ Tools\ ARM\ Embedded/4.6\ 2012q4/arm-none-eabi/lib/armv7-m/libc.ald.exe: cannot find -lC:/Program\ Files/GNU\ Tools\ ARM\ Embedded/4.6\ 2012q4/arm-none-eabi/lib/armv7-m/libc.awhich is your second suggestion then I think the command line has a good syntax even if it does not work no?