What's the proper way of using header-only library?
Asked Answered
M

3

13

I've ran into a confusion about how to properly use header-only library. Googling didn't help as I didn't find anything about using header-only libraries.

So my question is: Should I just copy the header files and paste them into my project folder and use them that way or should I link them to the project using C\C++ >> General >> Additional Include Directories?

Mcmullin answered 26/8, 2015 at 11:28 Comment(4)
Just include the header file in your source file? If you set up the header-file search paths correctly there's no need to copy any file.Rudolphrudwik
If you put the header in, e.g /ThirdParty/SomeLibrary/ then in the files that need those headers you just say #include "ThirdParty/SomeLibrary/SomeHeader.h"Ferrari
Do whatever you need to do to ensure that three years from now you can still check-out the project from source control and get it built. Copying files tends to make that easy of course. But not something you'd do with, say, Boost headers.Duhl
Thanks, guys! I think I'm going to end up copying headers into the project file since it's easier and more convenient(in my opinion).Mcmullin
E
5

I'd say copying the file to your project folder is preferable. That way your project is self contained. You could then give it to someone else and he would be able to build it without having to change any configuration.

Now, if you use boost which also has header-only libraries it is another story. Boost is easily obtainable and having your project depend on boost is less problematic. In that case I would add it in the Additional Includes.

Electromagnetism answered 26/8, 2015 at 11:35 Comment(0)
I
4

You can do either, it is really a question of convenience. Traditionally you would include them in your include path, but you can also put them in your project. Including them in your project makes it more self-contained and protects you from code-breaking library changes, but also means you have to install library security-related updates to each project's copy, for example.

Ignoble answered 26/8, 2015 at 11:42 Comment(0)
Q
0

Should I just copy the header files and paste them into my project folder and use them that way or should I link them to the project using C\C++ >> General >> Additional Include Directories?

I would say neither :-).

My suggestion would be to add the directory to the project's Configuration Properties/C++ directories/Include Directories folder. That way you can ensure that the library's directory is searched before other directories that might have a stale version of the library. Also, this allows having a single reference for the library from multiple projects.

Quincuncial answered 15/11, 2021 at 20:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.