Does this work?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Does this work?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Does this work?  
milkyway


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-29-05 11: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.






[ Post a follow-up to this message ]



    Re: Does this work?  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-29-05 11: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.





[ Post a follow-up to this message ]



    Re: Does this work?  
milkyway


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-29-05 11: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 ;-)






[ Post a follow-up to this message ]



    Re: Does this work?  
Brian Raiter


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-30-05 01:51 AM

> 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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:17 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register