The newlibc stubs are supposed to be included / linked in one code

During the build process of the project, the linker fails with the following errors unless I explicitly call one of the stub functions (i.e. _sbrk) in my code:

c:/toolchains/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libg.a(lib_a-abort.o): In function `abort':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\stdlib/../../../../../newlib-1.19.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
c:/toolchains/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libg.a(lib_a-signalr.o): In function `_kill_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
c:/toolchains/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libg.a(lib_a-signalr.o): In function `_getpid_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
c:/toolchains/yagarto/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib\libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.19.0/newlib/libc/reent/sbrkr.c:60: undefined reference to `_sbrk'
collect2: ld returned 1 exit status

      

I know I need some stub functionality that newlibc requires and I have a "C" file containing all of the above as missing and I am also sure the file is compiled and added to the archive file (* .a). which is later linked.

I am invoking the linker using the following commands

arm-none-eabi-gcc -L -T linkerscript.ld -nostartfiles -Wl,-Map,$(TARGET).map -lc archive.a

      

My question is simple (hopefully) How can I make sure the linker is linking my stubs in the elf file without having to explicitly call a function from one of my project files?

+3


source to share


2 answers


I think those errors you are getting are referring to a linker that cannot find the appropriate library. My first suspicion is in the way you use your arguments, specifically your archive directory (-L) and archive.a file specifications. I think it should look like this:

arm-none-eabi-gcc -L. -T linkerscript.ld -nostartfiles -Wl,-Map,$(TARGET).map -lc -larchive

      

where the changes will be made:



  • -L. means using the current directory to find library files for reference.
  • -lc indicates to use the archive file libc.a.
  • -larchive indicates to use the archive file libarchive.a.

For more information, I would suggest checking the GNU GCC link .

+3


source


Pass --verbose

in gcc

to see exactly where archive.a

shown in the list of libraries and objects passed to the linker.

You need to order things so that the search is archive.a

done after libg.a

, since it is an archive containing objects that end with undefined references.



You may be able to fix this by adding -lg

before archive.a

on the command line gcc

. -lg

should be in libg.a

earlier than when it pulls now by default and, more importantly, pull it in front archive.a

.

+2


source







All Articles