[问题]哪位大哥能告诉我gcc的-l参数是怎么工作的哈?

C、C++和Java语言
回复
头像
pjincz
帖子: 171
注册时间: 2007-02-07 10:15
送出感谢: 0
接收感谢: 9 次
联系:

[问题]哪位大哥能告诉我gcc的-l参数是怎么工作的哈?

#1

帖子 pjincz » 2007-02-26 17:35

昨天自己写了个小程序玩(呵呵,刚从windows跑过来什么都不会)
用了gtk/gtk.h 但是怎么编译就是缺少gtk.h文件。。。
呵呵,自己什么都不懂,就自以为是的把C_INCLUDE_PATH环境变量都设置好了。
搞了我4个小时,结果编译还是不通过。。。好像是缺少.a文件(我也是听同学说的,呵呵)
结果昨天折腾到2点多。。。
最后才发现只要编译的时候在后面加上-lgtk-x11-2.0参数就可以了。。汗死。。。
我查找了gtk-x11-2.0等文件,都没有发现什么有用的东西。。。
真是很难理解gcc的-l参数是怎么工作的。。。。
为什么一个-lgtk-x11-2.0就能解决从开始到include目录问题,到最后的lib文件目录。。
虽然问题解决了,但是知其然而不知其所以然很不爽。。。
呵呵 不知道哪位大哥懂的给小弟解说一下哈。。
先谢谢了哈。。
:roll: :roll: :roll: :roll:
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
送出感谢: 0
接收感谢: 7 次
联系:

#2

帖子 BigSnake.NET » 2007-02-26 17:40

-l library
Search the library named library when linking. (The second alter‐
native with the library as a separate argument is only for POSIX
compliance and is not recommended.)

It makes a difference where in the command you write this option;
the linker searches and processes libraries and object files in the
order they are specified. Thus, foo.o -lz bar.o searches library z
after file foo.o but before bar.o. If bar.o refers to functions in
z, those functions may not be loaded.

The linker searches a standard list of directories for the library,
which is actually a file named liblibrary.a. The linker then uses
this file as if it had been specified precisely by name.

The directories searched include several standard system directo‐
ries plus any that you specify with -L.

Normally the files found this way are library files---archive files
whose members are object files. The linker handles an archive file
by scanning through it for members which define symbols that have
so far been referenced but not defined. But if the file that is
found is an ordinary object file, it is linked in the usual fash‐
ion. The only difference between using an -l option and specifying
a file name is that -l surrounds library with lib and .a and
searches several directories.
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
kash
帖子: 23
注册时间: 2007-01-13 1:39
送出感谢: 0
接收感谢: 0
联系:

#3

帖子 kash » 2007-02-27 11:51

lgtk是libgtk的简化,就是说你需要libgtk-x11-2.0这个库才可以编译
回复

回到 “C/C++/Java”