Hi
I am trying to link some standard libraries using "ld" toolchain and facing issue while including the standard libraries.
I know using "gcc" is the better option as it always include standard libraries but i have same symbols reused so i can not use "gcc" option for linking.
Please let me know how i can link using "ld" and provide standard library such as libgcc or libc ?
For reference following is the command i am trying - Here my assumption is -lc command can link the libc library but i don't see it happens and i am still getting undefined reference to library function names.
compiler tool chain/ld -T {linkerscript} -lc a.o b.o -o final.bin
Has any one tried before statically linking standard library using ld ?
Thanks,
- ja
GNU LD linker option Issue statically linking standard libs
Re: GNU LD linker option Issue statically linking standard l
If you have using Makefile to compile, you are able to do it as follows:
Code: Select all
TARGET = foobar
LD := $(CROSS_COMPILE)ld
CC := $(CROSS_COMPILE)gcc
SRCS = foo.c bar.c main.c
OBJS = $(SRCS:.c=.o)
LIBS += $(shell $(CC) -print-file-name=libc.a)
LIBS += $(shell $(CC) -print-libgcc-file-name)
$(TARGET): $(OBJS)
$(LD) $(LDFLAGS) -T $(TARGET).lds $(OBJS) $(LIBS) -o $@
Last edited by Trex on Thu Jan 24, 2013 9:42 pm, edited 1 time in total.
Grrrrrrrrr...
Re: GNU LD linker option Issue statically linking standard l
Hi
Why are you still using the gcc for the libs ?
I suppose the $(LIBS) expands to $(CROSS_COMPILE)gcc -print-file-name=libc.a ?
Can you point me where to find information about -print-file-name ?
Thanks,
-ja
Why are you still using the gcc for the libs ?
I suppose the $(LIBS) expands to $(CROSS_COMPILE)gcc -print-file-name=libc.a ?
Can you point me where to find information about -print-file-name ?
Thanks,
-ja
Re: GNU LD linker option Issue statically linking standard l
I found the option -print-file-name=library option as part of gcc not ld...
Is there any way to pass directly to ld tool ?
Thanks,
- ja
Is there any way to pass directly to ld tool ?
Thanks,
- ja
Re: GNU LD linker option Issue statically linking standard l
I tried this solution and it doesn't work I am still getting undefined issue..
Thanks,
-ja
Thanks,
-ja
Re: GNU LD linker option Issue statically linking standard l
Sorry my mistake the solution works perfectly fine I found bug in my Makefile...
Thanks for the help !!
Regards,
- ja
Thanks for the help !!
Regards,
- ja
Re: GNU LD linker option Issue statically linking standard l
You need to specify libraries AFTER the object files because ld searches for undefined symbols only linearly and does not go back looking in previous libraries after it have found a new undefined symbol.ja wrote:Sorry my mistake the solution works perfectly fine I found bug in my Makefile...
Thanks for the help !!
Regards,
- ja
Learn to read.