简体   繁体   English

在gcc和g ++ include和lib路径中指定顺序

[英]Specifying order in gcc and g++ include and lib paths

I have multiple versions of a library, all with the same name (boost libraries), each installed in its own directory. 我有一个库的多个版本,都有相同的名称(boost库),每个都安装在自己的目录中。 I know how to instruct the compiler and linker to search in certain directories for header files and libraries ( -I and -L ). 我知道如何指示编译器和链接器在某些目录中搜索头文件和库( -I-L )。 I am also aware of how to pass the actual library file to the linker. 我也知道如何将实际的库文件传递给链接器。

My question is how to specify precedence in the search path of the compiler and the linker, such that it searches folder A before searching folder B and takes A 's version of the library instead of B 's . 我的问题是如何在编译器和链接的搜索路径指定优先级,使得其搜索文件夹A搜索文件夹之前B ,并采取A “库,而不是S版B S”。 I'm interested in order between all eligible directories, ie the default gcc and g++ ones, and the ones specified after -I and -L . 我对所有符合条件的目录(即默认的gccg++目录)以及-I-L之后指定的目录感兴趣。

My distro is Ubuntu 14.04 , and I use g++ 4.8 up to 6 . 我的发行版是Ubuntu 14.04 ,我使用g++ 4.86

GCC will search your -I directories in the left-to-right order in which they appear in your commandline and it will search all your -I directories before the default #include directories. GCC会搜索自己的-I目录在它们出现在你的命令行左到右的顺序,它会搜索所有-I默认目录之前#include目录。 Here is the documentation . 这是文档

GCC invokes the system linker, ld , to perform linkage. GCC调用系统链接器ld来执行链接。 Occurrences of GCC's -L option, and its -l option, are passed through to the linker with their order preserved. GCC的-L选项及其-l选项的出现将传递给链接器并保留其顺序。

The linker will search your -L directories in the left-to-right order in which they appear in the commandline and it will search all your -L directories before the default linkage directories. 链接器会搜索自己的-L目录在它们出现在命令行左到右的顺序,它会搜索所有-L默认联动目录之前,目录。 All of the -L options, in the order specified, apply to all of the -l options, regardless of how -L and -l options are intermixed in the commandline. 无论-L-l选项如何在命令行中混合,所有-L选项(按指定的顺序)都适用于所有-l选项。 Eg 例如

-La -lfoo -Lb -lbar

is equivalent to any of: 相当于以下任何一个:

-La -Lb -lfoo -lbar
-lfoo -La -Lb -lbar
-lfoo -lbar -La -Lb

Here is the documentation 这是文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM