linking with libraries not working..

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

linking with libraries not working..

Post by earlz »

Hi, I'm trying to get some basic userland stuff going, and one step is of course libc(I already got a common linker script and crt0 and such, so I can run a basic C app without a library)

So, I decided I was going to go a different route and synthesize my own libc out of BSD libcs out there(most notably OpenBSDs)

Well, I got all the string stuff copied in and made a nice generic makefile for it and got it to all compile. Then I put it into a library with

Code: Select all

/usr/cross/i586-elf/bin/ar crs ${OUTFILE} ${OBJS}
with OBJS being a list of objs and OUTFILE being libc.a

so libc.a goes into my lib directory and I make a simple C program that includes string.h and references strlen
the relevant part of my linker script is

Code: Select all

ENTRY (__main)

OUTPUT_FORMAT(binary)

STARTUP(../../lib/crt0.o)
SEARCH_DIR(../../lib)
and then I use on the ld command line for the application

Code: Select all

LDFLAGS = -nostartfiles -nodefaultlibs -nostdlib -lc
...
login.bin:	${OBJS}
	ld -T ../../A56.ld ${LDFLAGS} ${OBJS} -o ${OUTFILE}
and when linking it gives undefined symbol strlen. Well, but when I attach ../libc/strlen.o to OBJS it will link fine..

anyone see what I'm doing wrong here with lcreating and linking with this library?

edit:
oh wait, I didn't compile the sources with the cross compiler, only tried linking them.
but now I have a problem with my cross compiler. It didn't generate _types.h and cdefs.h files, and I tried copying them from my main compiler's include, but it doesn't work cause the cross compiler doesn't recognize __int32 and such things used internally
Post Reply