LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   newbie with a problem using ld (https://www.linuxquestions.org/questions/linux-newbie-8/newbie-with-a-problem-using-ld-608177/)

flauser 12-20-2007 12:47 PM

newbie with a problem using ld
 
I have both version 4.0.1 and 4.2.2 of gcc installed in my computer just in case that matters. I'm trying to link a small test program to learn to use the linker, but the linker can't seem to find the library, even under the indication to look for it under the current directory.

I had already obtained similar errors in past ocassions, that is to say, the linker doesn't find any libs even when I think I'm indicating both the correct name and the path using the -l and -L flags, respectively.

I've read the man files for both gcc and for ld, and I still can't pinpoint the error. I would really appreciate if anyone could help me out.

Code:


*** here are the files in the folder I am linking in

[prompt]$ ls

app.c
app.o
linker_error
temp_file.c
temp_file.o
test.c
testlib.a
test.o

*** here is the line that I used to link and the error I got:

[prompt]$ gcc -o app app.o -L. -ltest

/usr/bin/ld: cannot find -ltest
collect2: ld returned 1 exit status


colucix 12-20-2007 12:57 PM

When using the -l option the linker surrounds the name with "lib" and ".a ". This mean it looks for a file called libtest.a. If the library you're trying to link is testlib.a, you have to rename it as libtest.a.

flauser 12-20-2007 01:09 PM

thanks so much
 
right about now I am feeling pretty silly about not having noticed such a silly error, oh well, thanks a lot


All times are GMT -5. The time now is 06:35 PM.