简体   繁体   English

指定仅在g ++中提升到一个位置的包含路径

[英]Specifying include path to boost to one place only in g++

I am working on a code base that uses the boost libraries. 我正在开发一个使用boost库的代码库。 But, I recently ran into problems building the base on a new user's machine. 但是,我最近遇到了在新用户的机器上构建基础的问题。 I was able to boil the problem to the following. 我能够将问题归结为以下问题。 Here's how the build system looks like: 以下是构建系统的外观:

/root
    /SubModules_with_Makefiles_and_Code
    /thirdparty/boost

The submodule code will reference boost stuff like so (for example): 子模块代码将引用像这样的boost事件(例如):

#include <boost/property_tree/ptree.hpp>

And the sub module make files will build such a code like so (for example): 而子模块make文件将构建如此代码(例如):

g++ -c -o code.o code.cpp -I/root/thirdparty/boost

Our 3rd party boost library is version 1.37. 我们的第三方升级库是版本1.37。 However, some modules have begun using later versions of boost. 但是,一些模块已经开始使用更高版本的boost。 This problem has been masked because the machines where these modules have been built contain boost 1.41 installed in /usr/include/boost. 此问题已被屏蔽,因为构建这些模块的计算机包含安装在/ usr / include / boost中的boost 1.41。

The problem came to bear because the new user's machine did not have boost 1.41 installed in /usr/include. 问题来了,因为新用户的机器没有安装在/ usr / include中的boost 1.41。 Ideally, I would like g++ to look for boost in the third party directory and nowhere else. 理想情况下,我希望g ++在第三方目录中寻找提升,而不是其他地方。 This way, we can have tighter control of how the code base gets built. 这样,我们就可以更严格地控​​制代码库的构建方式。

-I<dir> places <dir> before the system includes during lookup, but system includes are still looked at and that is where later versions of boost can be installed depending on the machine. -I <dir>在查找期间系统包含之前放置<dir>,但仍然会查看系统包含,并且可以根据计算机安装更高版本的boost。 I can suppress looking at the system includes, but that would be a real pain. 我可以抑制看系统包含,但那将是一个真正的痛苦。

Is there anyway smart way to go about this, other than replacing: 除了替换之外,还有什么聪明的方法可以解决这个问题:

#include <boost/something.hpp>

to

#include <thirdparty/boost/something.hpp>

? If it helps, I am using gnu make 3.81 and g++ 4.4.5 on redhat linux. 如果有帮助,我在redhat linux上使用gnu make 3.81和g ++ 4.4.5。

Look at the 'include path' command line option (-I). 查看'include path'命令行选项(-I)。 You can set where it searches for included files. 您可以设置搜索包含文件的位置。 Documentation here 文档在这里

You might want to take a look at section 2.3 of the gcc manual: http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html 您可能需要查看gcc手册的第2.3节: http//gcc.gnu.org/onlinedocs/cpp/Search-Path.html

The compiler switch you are looking for would most probably be 您正在寻找的编译器开关很可能是

-nostdinc

But better take a look yourself. 但最好自己看看。

EDIT: oop, I just saw you DONT want to disable the default search path - in that case just use the -I switch: 编辑:oop,我刚看到你不想禁用默认搜索路径 - 在这种情况下只需使用-I开关:

You can add to this list with the -Idir command line option. 您可以使用-Idir命令行选项添加到此列表。 All the directories named by -I are searched, in left-to-right order, before the default directories. 在默认目录之前,按从左到右的顺序搜索-I命名的所有目录。

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

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