I use a code with different libraries, which use names like defines.h. This does not only cause conflicts for identical filenames, but also creates confusion. From which library is the defines.h include?
Including as #include <library/defines.h> would be a clean solution, but then the include path would need to be the parent directory of the library, which is rather unclean again.
Is there some way to alias the include path, so that -I/path/to/library makes the headers available under library/headername.h?
2 Answers 2
Is there some way to alias the include path, so that
-I/path/to/librarymakes the headers available underlibrary/headername.h?
There seems to be no need to in this case. You can simply use -I/path/to which makes /path/to/library/headername.h available under library/headername.h.
That said, while there is no such compilation option (that I know of), you can create such "aliases" to file paths in most file systems. These aliases are called symbolic links. In this case, you could make a link /path/to/library/mylibrary that points to . which would make /path/to/library/headername.h available under mylibrary/headername.h assuming you've used -I/path/to/library.
6 Comments
headername.h depends on headerutil.h, it typically pulls things in using #include "headerutil.h". With this approach, such dependencies would break.#include "headerutil.h" would not break (not in GCC anyway). If headerutil.h is in same directory as headername.h, then that is the first location where it will be looked for regardless of any include directory options.#include "L2/B.h". If you're developing these libraries you can set them up. If not, you could transform the headers, since they're of no semantic significance (the only downside, outside of getting it right, is having to do it each update).At least on unixy systems, when you compile and install a library, headers are installed for example to
/usr/lib/libraryname/*.h
Or maybe something like
/opt/libraryname-1.2/include/libraryname/*.h
And then if necesssry (not installing to compiler's default include search path), right dir is added with compiler option, for gcc for example option
-I/opt/libraryname-1.2/include
Then just always do this in source code, trusting build system to have included the right search paths:
#include <libraryname/includefile.h>
2 Comments
library/.. can contain all sort of things I would not like to have in the include path. And I have no idea, where the user later will put his libs. The cmake variables are there, so he can have /path/to/somelib-x.y, but I do not know the x.y in advance either.I in (-I or /I) a set of base directories, then as far as you're concerned everything may as well be in the same directory (the only difference is inclusion order of shared include paths which, I would argue, you should strive to design your way out of relying on anyway).
-I/path/to/library:mylibraryand then I can use the files in the folder asmylibrary/headerfile.h, where mylibrary is an alias for the full path.import foo as bar, but whatdefines.his included in C depends on the order of include paths./usr/includework. Although variations exist, many libraries expect the the include path to be-I/usr/include, so that headers can be included with a unique prefix exactly matching the directory structure.