Linking Libraries

C

crash_zero

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.

Thanks.
 
M

Michael Mair

crash_zero said:
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.

->
is the rigth place to ask.

<OT>Have a look at the -l and -L options.

Did your lecturer tell you nothing about gcc?

If so, consider using the options "-ansi -pedantic -Wall -O"
all the time -- this will warn you about many potential errors
and compile only standard C programs.
</OT>

Cheers
Michael
 
R

Richard Heathfield

crash_zero said:
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
 
J

junky_fellow

Richard said:
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
I think -I is used to tell where the header files are.
 
M

Michael Mair

Richard said:
crash_zero wrote:





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
^^
ITYM -L
-lcrack # but all on one line, of course

Cheers
Michael
 
R

Richard Heathfield

I think -I is used to tell where the header files are.

I said -L, not -I. Your monitor is faulty. So is the monitor of anyone else
who notices this *apparent* problem with what I actually wrote, which was
-L, not -I.

And if you try copying the line into a shell and running it past gcc and gcc
complains, then your gcc installation is buggy. And so is your friend's
copy. And his friend's.

And if RMS says that it sure looks like -I to him, I would suggest that he
should consult an expert instead of making foolish complaints all the time.
 
J

junky_fellow

Richard said:
I said -L, not -I. Your monitor is faulty. So is the monitor of anyone else
who notices this *apparent* problem with what I actually wrote, which was
-L, not -I.

And if you try copying the line into a shell and running it past gcc and gcc
complains, then your gcc installation is buggy. And so is your friend's
copy. And his friend's.

And if RMS says that it sure looks like -I to him, I would suggest that he
should consult an expert instead of making foolish complaints all the time.

Instead of blaming others, first check yours.
 
C

crash_zero

Dear all,

Thank you for your help. I have managed to solve my problem. =)

Thanks
 
J

junky_fellow

Richard said:
I suggest you read the sig block in my previous article a little more
closely.
I had seen that earlier. I knew what your intentions were. I respect
you a lot as you are and always been helpful. But that doesn't mean
that experts don't make mistake. Its not that if an expert types "I"
it would itself become "L". I just wanted to point out that you made
some mistake (may be in hurry). And you should admit that gracefully.
 
K

Keith Thompson

I had seen that earlier. I knew what your intentions were. I respect
you a lot as you are and always been helpful. But that doesn't mean
that experts don't make mistake. Its not that if an expert types "I"
it would itself become "L". I just wanted to point out that you made
some mistake (may be in hurry). And you should admit that gracefully.

He did. He simply chose to do so in a humorous manner. If you took
his remarks seriously (such as "Your monitor is faulty"), you
misunderstood.

Moving on ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,226
Latest member
KristanTal

Latest Threads

Top