链接库 [英] Linking Libraries

查看:80
本文介绍了链接库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在写一个程序,我必须使用一个库,我的讲师

传递给我,我不确定如何链接库。


我的程序名是module.c,我的库是crack.a。它位于

我文件夹中的/ lib目录。


我正在使用gcc。


谢谢。

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.

推荐答案

crash_zero写道:
crash_zero wrote:


我写的一个程序,我必须使用我的讲师传给我的图书馆,我不知道如何链接库。

我的程序名称是module.c和我的库是破解。它位于我文件夹中的/ lib目录中。

我正在使用gcc。
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.




- >新闻:gnu.gcc.help


是最难问的地方。


< OT>看看-l和-L选项。


您的讲师没有告诉您任何关于gcc的信息吗?


如果是这样,请考虑使用选项-ansi -pedantic -Wall -O"

- 这会警告你许多潜在的错误

并且只编译标准C程序。

< ; / OT>


干杯

Michael

-

电子邮箱:我的是an / at / gmx / dot / de address。



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


crash_zero写道:
crash_zero wrote:

我正在编写一个程序,我必须使用我的讲师传给我的库,我不知道如何链接库。

我的程序名称是模块。 c和我的图书馆是crack.a。它位于我文件夹中的/ lib目录中。

我正在使用gcc。
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.



你真的应该在gcc中问这个新闻组。这就是gcc

专家们所在的地方。但是要付出代价,我会告诉你的。价格是这样的:下一个

你搭乘公共汽车的时间和一个陌生人在同一站的公共汽车上下车,你支付他们的票价和你自己的票价。如果你从来没有去过公共汽车,那么另外的价格就是在接下来的三个月内提取和妥善处理50块

垃圾。


如果我们达成协议,请继续阅读:


...


...


...


...


...


这是一个相当正常的gcc线,没有库位,紧接着是一个链接libmymasterpiece.a的
,这样你就可以清楚地看到哪个是
部分这条线与图书馆有关:


gcc -W -Wall -ansi -pedantic -O2 -o foo foo.c

gcc -W -Wall -ansi -pedantic -O2 -o foo foo.c -lmymasterpiece


这不是那么难,但请注意该行假设库在

表格libTHENAME.a - lib和.a默默地放弃了。由于你的
库名不是那种形式,你将会挣扎。将libcrack.a的名称改为

(然后使用-lcrack作为链接选项),或者,如果

这是不可接受的,请在gcc组中询问专家协助。


现在,你提到你有某种文件夹。我不知道

是什么意思,但我看到你有一个/ lib目录。我想你的意思是

类似于:/ home / crashzero / lib - 我是对的吗?如果是这样,那么你会使用

-I标志告诉gcc这个:


gcc -W -Wall -ansi -pedantic -O2 -o模块-I / home / crashzero / lib module.c

-lcrack#但所有在一行上,当然

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

邮件:rjh在上面的域名


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




Richard Heathfield写道:

Richard Heathfield wrote:
crash_zero写道:
crash_zero wrote:


我正在写一个程序,我必须使用我的讲师传给我的图书馆我不知道如何链接库。

我的程序名是module.c,我的库是crack.a。它位于我文件夹中的/ lib目录中。

我正在使用gcc。
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.



你真的应该在gcc中问这个新闻组。这就是gcc专家们所在的地方。但是要付出代价,我会告诉你的。价格是这样的:下一次
你赶上公共汽车的时间和陌生人在同一站的公共汽车上下车,支付他们的票价和你自己的票价。如果你从来没有去过公共汽车,那么替代价格就是在接下来的三个月内收拾并妥善处理掉五十块垃圾。

如果我们有交易,请继续阅读:

...

...

...

...

...

这是一个相当普通的gcc系列,没有一个库位,紧跟着一个链接libmymasterpiece.a的链接,这样你就可以清楚地看到了这部分线与图书馆有关:

gcc -W -Wall -ansi -pedantic -O2 -o foo foo.c
gcc -W -Wall -ansi -pedantic -O2 -o foo foo.c -lmymasterpiece

这并不是那么难,但请注意该行假定库是
形式的libTHENAME.a - ; LIB"和.a默默地放弃了。由于你的图书馆名称不是那种形式,你会挣扎。要么将名称更改为libcrack.a(然后使用-lcrack作为链接选项),或者如果
这是不可接受的,请在gcc组中寻求专家帮助。

现在,你提到你有某种文件夹。我不知道那意味着什么,但我看到你有一个/ lib目录。我想你的意思是
类似于:/ home / crashzero / lib - 我是对的吗?如果是这样,那么你会使用-I标志告诉gcc这个:

gcc -W -Wall -ansi -pedantic -O2 -o module -I / home / crashzero / lib module.c
-lcrack#但所有在一行上,当然


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.


这篇关于链接库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆