anyone else having problems with libraries under LD?
Posted: Sat Jun 02, 2007 3:21 pm
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?
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?