Reputation: 4928
I'm getting more confident with C++ to the point where I'm beginning to experiment with some 3rd party libraries. I'm currently trying to integrate the Aquila DSP C++ library within a Qt project. I've come across an issue regarding the headers within the library.
Navigating through the library, I notice that some of the includes use search path statements such as
#include "../../global.h"
What I'm getting from this is.. I shouldn't EVER modify the file structure within the library. For example, let say I naively remove all subfolders within the library such that every single file is contained within the same directory. By doing this, I would essentially be breaking the library, and I would have to redefine the file paths for all of the includes... correct?
This brings me to another question. If I'm using a library within the project, what is the best practice on where I should store this library? Would it be best practice to have the library in one location on my computer, and be able to reference it from multiple projects? Or is it better to create an instance (copy) the library to whatever directory contains my project?
I appreciate any help!
Upvotes: 1
Views: 858
Reputation: 4865
Some good practices are using a directory tree that maps your namespace structure (see boost lib).
Relative paths to the current file may be difficult to maintain. The practice usually is to add search paths via the -I
flag or equivalent compiler setting, then use all headers as if they where under your current file path.
This is easy to maintain if you use a project manager or a makefile.
If your project uses some external library that isn't expected to be preinstalled, you can add them all together under an external
or deps
folder, to make it clear to the maintainer that he should probably ignore that folder content.
On posix systems, standard libs go under /usr/lib, headers under /usr/include and resources under /usr/share. Libs compiled and installed by the user go under /usr/local/lib, /usr/local/include and /user/local/share.
Upvotes: 2
Reputation: 458
Correct. If you put all headers in the same directory you have to update all the include directives.
The best practise is to put your library somewhere in your computer and references it. You have to use the -I directive of the compiler. For instance g++ -I/your/lib/dir/headers ... Then use simple include directive in your source code.
Upvotes: 1