crash_zero wrote:
Hi,
I am writing a program and I have to use a library which my lecturer
passed to me and I'm not sure how to link the libraries.
My program name is module.c and my library is crack.a. It is located in
the /lib directory in my folder.
I am using gcc.
You really ought to ask this in a gcc newsgroup. That's where the gcc
experts hang out. But for a price, I'll tell you. The price is this: next
time you catch a bus and a stranger gets on the bus at the same stop as
you, pay their fare as well as your own. If you never, ever catch buses,
the alternative price is to pick up and dispose properly of fifty pieces of
litter over the next three months.
If we have a deal, read on:
...
...
...
...
...
Here's a fairly normal gcc line WITHOUT a library bit, followed immediately
by one that links libmymasterpiece.a, so that you can clearly see which
part of the line relates to the library:
gcc -W -Wall -ansi -pedantic -O2 -o foo foo.c
gcc -W -Wall -ansi -pedantic -O2 -o foo foo.c -lmymasterpiece
That's not so hard, but note that the line assumes the library is in the
form libTHENAME.a - the "lib" and ".a" are silently dropped. Since your
library name isn't in that form, you are going to struggle. Either change
the name to libcrack.a (and then use -lcrack as your link option) or, if
that's not acceptable, ask in a gcc group for expert assistance.
Now, you mention that you have some kind of "folder". I don't know what that
means, but I see that you have a /lib directory in it. I guess you mean
something like: /home/crashzero/lib - am I right? If so, then you would use
the -I flag to tell gcc about this:
gcc -W -Wall -ansi -pedantic -O2 -o module -I/home/crashzero/lib module.c
-lcrack # but all on one line, of course
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain