gcc:-L和-l选项之间的区别以及如何提供库的完整路径 [英] gcc: Difference between -L and -l option AND how to provide complete path to a library
问题描述
我是makefile的新手.因此,如果我的问题很琐碎,请接受我的道歉.
I am new to makefile stuff; so, please accept my apology if my questions are trivials.
问题1 :-L和-l选项有什么区别.
Question 1: What is the difference between -L and -l option.
问题2 :您如何提供通往某些图书馆的完整路径?例如,以下makefile中提到的"libeng"和"libmx"位于{MATLABROOT}/bin/glnxa64
Question 2: How do you provide complete path to some library? For instance, "libeng" and "libmx", mentioned in following makefile,are located at {MATLABROOT}/bin/glnxa64
# root directory of MATLAB installation
MATLABROOT="/usr/local/MATLAB/R2011b"
all: engdemo
engdemo:
g++ ${MATLABROOT}/extern/examples/eng_mat/engdemo.cpp -o engdemo \
-I${MATLABROOT}/extern/include \
-L${MATLABROOT}/extern/lib -llibeng -llibmx
clean:
rm -f engdemo *.o
更新: 以下makefile起作用:
Update: Following makefile works:
# root directory of MATLAB installation
MATLABROOT="/usr/local/MATLAB/R2011b"
all: engdemo
engdemo:
g++ ${MATLABROOT}/extern/examples/eng_mat/engdemo.cpp -o engdemo \
-I${MATLABROOT}/extern/include \
#-L${MATLABROOT}/extern/lib -llibeng -llibmx
-L${MATLABROOT}/bin/glnxa64 -llibeng \
-L${MATLABROOT}/bin/glnxa64 -llibmx
clean:
rm -f engdemo *.o
我发现以下有关链接库的链接非常有用: http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries .html
I found following link about linking libraries very useful: http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html
推荐答案
您的问题是指gcc
链接程序(或简称为ld
).
可以在gcc
的链接选项中找到说明,或ld
的命令行选项.
Your question is refering to gcc
linker (or simply ld
).
Discription can be found in in gcc
's Options for Linking or ld
's Command Line Options.
从文档中获取
-存档 将存档文件存档添加到要链接的文件列表. ld将在其路径列表中搜索指定的每个存档的libarchive.a的出现.
-larchive Add archive file archive to the list of files to link. ld will search its path-list for occurrences of libarchive.a for every archive specified.
-Lsearchdir 将路径searchdir添加到ld将搜索存档库和ld控制脚本的路径列表中.
-Lsearchdir Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts.
在您的示例中,您需要使用-L
定义libeng
和libmx
库所在的路径.然后使用-l
选项指示ld
使用这些库.
In your example you need to use -L
to define the path where libeng
and libmx
libraries are located. Then use -l
option to instruct ld
to use these libraries.
请注意,在文档中指出:
Note that in the documentation is noted that:
ld将在其路径列表中搜索指定的每个 archive 的lib archive .a的出现.
ld will search its path-list for occurrences of libarchive.a for every archive specified.
这篇关于gcc:-L和-l选项之间的区别以及如何提供库的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!