anyone else having problems with libraries under LD?

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

anyone else having problems with libraries under LD?

Post by earlz »

Well, I discovered probably the stupidest thing about LD about 3 days ago..
I was attempting to make a test library..The library was made simply and everything..then I tried to test it to see if it worked..well first I had some trouble getting -lmy_lib to work, but I fixed that by adding -L. to put the current dir into the library search path.. then all I got was undefined references! I tried everything..and it was only with the library file that it didn't work, it worked with the object file!

ok, my makefile line to link the test program was "ld -o my_test.exe -lmy_lib obj/my_test.o"
no warnings or anything... just undefined reference errors..

then.. I just deleted -lmy_lib and tried doing something else..then I added -lmy_lib to the end(after obj/my_test.o) and voila! it worked!!

so basically to link a library with a program, it MUST be after the object file list..of course, if you put it before that list, then it will not give warnings or errors or anything..it just silently won't work, leaving you trying to figure out what the F**k is wrong with your compiler and linker...

just thought I'd share this..it took me about 4 hours to figure out so..


btw, any real reason why LD does this?
niteice
Member
Member
Posts: 59
Joined: Tue Oct 03, 2006 3:49 pm

Post by niteice »

Why use ld? Is there some pressing reason you can't just let gcc handle the link phase (which calls ld anyway)?
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

I tried it with g++ and it did the same thing..didn't try it with gcc
Post Reply