Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install third party libraries

I'm sorta new to C++ and I've decided to try and use odeint to do some simulations because python is too slow for my needs.

I found this package, which I want to play with. I'm just not totally sure how to install or where to place these libraries. Is there something for C++ similar to python's pip install?

Side note: I'm trying to do this using Eclipse Kepler, but I'm not married to that idea.

like image 538
Matt Avatar asked Feb 21 '14 18:02

Matt


1 Answers

I recommend not putting the code into your own project - that is a rather quick and dirty solution. The correct way to use a library in C++ (in fact, in any programming language that I know) is to keep all libraries separate from your own projects, at a separate location on your filesystem.

You then tell your environment where to find the library files and tell your project to use them. It's always the same basic idea, whether you are using Makefiles or Visual Studio project files.

Look at the documentation of this library. It says:

odeint is a header-only library, no linking against pre-compiled code is required

This means that the "library files" I just mentioned are just header files. That makes it much easier for you, because you don't have to deal with linker options. In C++, the location where additional (project-external) header files can be found is usually called the "include path".

Your new problem should therefore be: How to tell Eclipse Kepler my include path?

Entering this new problem into Google (as "eclipse kepler include path") yields a few interesting results. It will eventually lead you to the Eclipse documentation about include paths, where you can learn how to edit the C++ include path.

Now that everything is set up, you can finally use the library's header files in your projects via lines like the following:

#include <boost/numeric/odeint.hpp>

Do you notice the < >? They make a big difference, because they are the C++ way of saying "this is not part of my project, please get it from my include path". Just like headers which are part of the language (e.g. <vector> or <iostream>).

All of this may appear troublesome at first, and perhaps you even gain little from it at the beginning, but in the long run, for many different projects and many different libraries, it's the only way to prevent chaos.

like image 52
Christian Hackl Avatar answered Nov 03 '22 10:11

Christian Hackl