Library include paths with same header name(库包含具有相同标题名称的路径)
问题描述
What is the best method to include a file that has same name in another folder from additional include directories?
Example:
lib1/include/foo.h
lib2/include/foo.h
where both lib1/include and lib2/include are added in additional include directories.
Edit:
The libs are from different SDK's and every developer installs them in his own place. Only thing that is sure is that both folders are in IDE's additional include paths
method 1:
#include "../../lib1/include/foo.h
method2:
Add lib1/include before lib2/include in search paths and because they are searched in order with:
#include "foo.h"
lib1/include/foo.h will be included
First off, this answer assumes that the include guards for the two headers are compatible (i.e. not the same symbols).
One thing you can do is create links in known locations to the header files of interest, giving the links themselves distinct names. For example, say your two libraries are installed at $LIB1PATH and $LIB2PATH, which could have different values in different build environments. Thus the headers you want to get are at $LIB1PATH/include/foo.h and $LIB2PATH/include/foo.h.
You could go two ways with this. One is by creating direct links. This could look like this in your project's directory tree:
$PROJDIR/
include/
lib_include/
lib1_foo.h -> $LIB1PATH/include/foo.h
lib2_foo.h -> $LIB2PATH/include/foo.h
src/
This could get tricky if your code is in a repository, because you couldn't check these links in; they'd be wrong in other environments. Also, if you have a lot of these links and few libraries, you'd have to recreate all of them whenever lib1 or lib2 move... not cool. You can get around this problem by creating links in the directory that contains the project's directory:
$PROJDIR/
include/
lib_include/
lib1_foo.h -> ../../lib1/include/foo.h
lib2_foo.h -> ../../lib2/include/foo.h
src/
lib1 -> $LIB1PATH/
lib2 -> $LIB2PATH/
In both cases, you need to make sure $PROJDIR/lib_include
is on your include path. Also, you only need to have $LIB1PATH/include
and $LIB2PATH/include
in your include path if the two foo.h
headers pull in more headers from those directories. You could also put the links in include
and get rid of lib_include
, but I like keeping these things separate.
这篇关于库包含具有相同标题名称的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:库包含具有相同标题名称的路径
- C语言手把手带你掌握带头双向循环链表 2023-04-03
- 我应该为我的项目使用相对包含路径,还是将包含目录放在包含路径上? 2022-10-30
- c++ const 成员函数,返回一个 const 指针.但是返回的指针是什么类型的 const? 2022-10-11
- ubuntu下C/C++获取剩余内存 2023-09-18
- C语言qsort()函数的使用方法详解 2023-04-26
- Qt计时器使用方法详解 2023-05-30
- C++ 数据结构超详细讲解顺序表 2023-03-25
- C语言详解float类型在内存中的存储方式 2023-03-27
- 详解C语言中sizeof如何在自定义函数中正常工作 2023-04-09
- Easyx实现扫雷游戏 2023-02-06