|
Home > Archive > Unix Programming > August 2005 > Does this work?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| milkyway 2005-08-29, 6:00 pm |
| Hello,
I am having problems compiling a C program with a library.
I have a library that I created this way:
ar rs libtest.a onefile.o
Then, I tried created a file (test_query.c) that has a 'main'. It
references the function sitting in 'onefile.o'
I then tried to compile test_query.c as follows:
gcc -I/demo/ test_query test_query.o -L/demo/ -ltest.a
I get the following error:
/usr/bin/ld: cannot find -l/demo/test.a
I guess I do not understand why this does not work. I have specified
the entire path to the library but it continues to say that it never
finds it.
What's wrong?
Any help, hints or advice appreciated.
| |
| Paul Pluzhnikov 2005-08-29, 6:00 pm |
| "milkyway" <d0mufasa@hotmail.com> writes:
> I then tried to compile test_query.c as follows:
No, you didn't *compile* test_query.c with that command.
Presumably you have already compiled it, and now you are *linking*
test_query.o
> gcc -I/demo/ test_query test_query.o -L/demo/ -ltest.a
>
> I get the following error:
> /usr/bin/ld: cannot find -l/demo/test.a
That's expected. Correct link command is:
gcc -o test_query test_query.o -L/demo -ltest
^^ ^^
> I guess I do not understand why this does not work. I have specified
> the entire path to the library but it continues to say that it never
> finds it.
>
> What's wrong?
From 'info ld':
`-lARCHIVE'
`--library=ARCHIVE'
Add archive file ARCHIVE to the list of files to link. This
option may be used any number of times. `ld' will search its
path-list for occurrences of `libARCHIVE.a' for every ARCHIVE
specified.
Note that the linker automatically adds 'lib' prefix and '.a' suffix.
Your original command asked linker to find libtest.a.a, which
(apparently) does not exist on your system.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
| |
| milkyway 2005-08-29, 6:00 pm |
| I will try that as well. I had added my library to LD_LIBRARY_PATH and
that seemed to do OK ;-/
A nasty hack.
Will try this too. Thanks ;-)
| |
| Brian Raiter 2005-08-29, 8:51 pm |
| > I then tried to compile test_query.c as follows:
>
> gcc -I/demo/ test_query test_query.o -L/demo/ -ltest.a
>
> I get the following error:
> /usr/bin/ld: cannot find -l/demo/test.a
If you're using the -l switch, then you need to leave off the .a:
gcc -I/demo/ test_query test_query.o -L/demo/ -ltest
Alternately, you can explicitly name the .a file on the commandline:
gcc -I/demo/ test_query test_query.o /demo/libtest.a
gcc will figure out from the file type that it's a static library and
do the right thing. Personally, I favor this syntax when linking with
static libraries that aren't installed by the system.
b
|
|
|
|
|