473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Linking Libraries

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.

Nov 15 '05 #1
11 1330
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.


-> news:gnu.gcc.help

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
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #2
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
Nov 15 '05 #3

Richard Heathfield wrote:
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

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

Nov 15 '05 #4
Richard Heathfield wrote:
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

^^
ITYM -L -lcrack # but all on one line, of course


Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #5
ju**********@yahoo.co.in wrote:

Richard Heathfield wrote:

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.


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.

--
Richard Heathfield
"Oops. Yeah, I meant -L" - rjh 20/8/2005
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #6

Richard Heathfield wrote:
ju**********@yahoo.co.in wrote:

Richard Heathfield wrote:

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.


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.

Nov 15 '05 #7
Dear all,

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

Thanks

Nov 15 '05 #8
ju**********@yahoo.co.in wrote:

Richard Heathfield wrote:

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.


I suggest you read the sig block in my previous article a little more
closely.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #9

Richard Heathfield wrote:
ju**********@yahoo.co.in wrote:

Richard Heathfield wrote:

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.


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.

Nov 15 '05 #10
ju**********@yahoo.co.in writes:
Richard Heathfield wrote:
ju**********@yahoo.co.in wrote:
>
> Richard Heathfield wrote:
>>
>> 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.


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.


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 ....

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #11
Richard Heathfield wrote:
ju**********@yahoo.co.in wrote:

Richard Heathfield wrote:
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.

I suggest you read the sig block in my previous article a little more
closely.


Some of us laughed quite enough without the sig. Thanks, Richard.
Nov 15 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Rob Ratcliff | last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray X1. It makes heavy use of templates and namespaces. Up until the link step, the C++ source code compiled flawlessly. But, when...
2
by: sunil | last post by:
Hi, We have lot of c and fortran archive libraries that have complex dependencies. We have different server tasks that use some of these libraries. We have developed a tool inhouse that links...
2
by: Ian | last post by:
I've downloaded 3rd party libraries and I'm trying to link them in with my code but when I use -l<library name> it gives me the error "ld: cannot find -l<lib name>". When I link the libraries...
2
by: Joerg M. Colberg | last post by:
I have a VS.Net solution that contains various projects. Some of the projects contain programme blocks (legacy code) that are used by some of the other projects. One project contains some C code...
10
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
7
by: Hal Vaughan | last post by:
I have a problem with port forwarding and I have been working on it for over 2 weeks with no luck. I have found C programs that almost work and Java programs that almost work, but nothing that...
3
by: walkeraj | last post by:
I'm trying to compile an open source game called IVAN , and I'm able to compile it from a makefile, but not from an IDE. I have attempted to recreate the way the makefile compiles the project as...
4
by: Richard | last post by:
First question - let's get this out of the way since it might be the solution to all my woes: Does it make sense to have a .cpp file for a class that is declared as having pure virtual functions...
2
by: Manuel T | last post by:
Hello everybody, I'm trying to port a project from Windows+Cygwin to Linux(i'm working on a Debian-like: Kubuntu), but I'm facing a lot of linking problems. This project needs libraries xerces...
1
by: rsennat | last post by:
Hi, what is the order of the libraries in the Makefile, for linking inter dependent libraries. i'm getting linker error for the following scenario. I have lib1.a and lib2.a, with which lib1.a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.