gcc 中-lfoo表示啥意思。 这个中gcc foo.c -L /home/lib -lfoo -o hello

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gcc 中-lfoo表示啥意思。 这个中gcc foo.c -L /home/lib -lfoo -o hello相关的知识,希望对你有一定的参考价值。

请各位说明,谢谢

下面是man gcc里面的介绍。
比较靠后,我的结果大概是8113到8140行.
简单的讲就是foo这个库的链接查找方法。详细内容,,请看下面的英文。。。。。或者自己man gcc 查看8113到8140行的内容。

-llibrary
-l library
Search the library named library when linking. (The second
alternative 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
directories 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
fashion. 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.追问

-lfoo这个库是自己弄的吗,还是会生成

gcc 中-lfoo表示什么意思。 这个中gcc foo.c -L /home/lib -lfoo -o hello 这个的-lfoo是在/home/lib已有的foo库吧

追答

这段英文包含了好几种情况。具体讲,-lfoo使用的是标准库(或者说系统目录里的库?)里的foo,而非你这个目录自己制作的foo.
实在不行的话。个人觉得最好是自己测试。方法是:自己编写的库里写点特别的。然后区分不同情况看结果。

参考技术A 如果你是初学者,并且正在看Linux的书的话。那么-lfoo的意思应该是访问库foo,其中l表示访问,lib表示库,libfoo即库foo。
-lfoo选项指示编译器使用名为libfoo.h的函数库(或者名为libfoo.c的共享库,如果它存在的话)。
EG:库sort叫做libsort,调用时为-lsort。

linux命令gcc–static式啥意思

gcc 空格 -static 吧?

-static 是让 gcc 进行静态编译,也就是把所有都需要的函数库都集成进编译出来的程序上,这个程序就可以不依赖外部的函数库运行了。来自:求助得到的回答
参考技术A 静态编译可执行文件,避免使用动态库的方式。 参考技术B 生成静态库? 参考技术C 静态编译文件

以上是关于gcc 中-lfoo表示啥意思。 这个中gcc foo.c -L /home/lib -lfoo -o hello的主要内容,如果未能解决你的问题,请参考以下文章

GCC 中 -x 标志的输入和输出“语言”是啥意思?

linux命令gcc–static式啥意思

icpc(或我猜是gcc)的预处理输出中的包含路径/数字是啥意思?

gcc 警告“在 GCC 7.1 中为 X 传递的项目参数已更改”是啥意思?

CompileError/LinkerError: "command 'gcc' failed with exit status 1" 是啥意思,在 IPython 中运行 %%c

gcc get_http.c –lcurl啥意思