gcc:-L 和 -l 选项之间的区别以及如何提供库的完整路径 [英] gcc: Difference between -L and -l option AND how to provide complete path to a library
问题描述
我是 makefile 的新手;所以,如果我的问题是琐碎的,请接受我的道歉.
问题1:-L和-l选项有什么区别.
问题 2:您如何提供某些库的完整路径?例如,以下makefile中提到的libeng"和libmx"位于{MATLABROOT}/bin/glnxa64
#MATLAB安装根目录MATLABROOT="/usr/local/MATLAB/R2011b"全部:engdemo演示:g++ ${MATLABROOT}/extern/examples/eng_mat/engdemo.cpp -o engdemo -I${MATLABROOT}/extern/include -L${MATLABROOT}/extern/lib -llibeng -llibmx干净的:rm -f 工程演示 *.o
更新:以下makefile有效:
#MATLAB安装根目录MATLABROOT="/usr/local/MATLAB/R2011b"全部: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干净的:rm -f 工程演示 *.o
我发现以下关于链接库的链接非常有用:http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html
您的问题是指 gcc
链接器(或简称为 ld
).描述可以在 gcc
的 Options for链接或ld
的命令行选项.
从您获得的文档中
<块引用>-larchive将归档文件归档添加到要链接的文件列表中.ld 将在其路径列表中搜索每个指定存档的 libarchive.a.
<块引用>
-Lsearchdir将路径 searchdir 添加到 ld 将搜索归档库和 ld 控制脚本的路径列表中.
在您的示例中,您需要使用 -L
来定义 libengcode> 和
libmx
库所在的路径.然后使用 -l
选项来指示 ld
使用这些库.
请注意,在文档中指出:
<块引用>ld 将在其路径列表中搜索每个指定的 archive 出现的 libarchive.a.
I am new to makefile stuff; so, please accept my apology if my questions are trivials.
Question 1: What is the difference between -L and -l option.
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
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
I found following link about linking libraries very useful: http://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html
Your question is refering to gcc
linker (or simply ld
).
Description can be found in in gcc
's Options for Linking or ld
's Command Line Options.
From the documentation you get
-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 Add path searchdir to the list of paths that ld will search for archive libraries and ld control scripts.
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 will search its path-list for occurrences of libarchive.a for every archive specified.
这篇关于gcc:-L 和 -l 选项之间的区别以及如何提供库的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!