How to add Eigen library to c++ project
Asked Answered
S

5

6

Probably a dumb / simple question, but I have not been able to find an answer. I have no clue how adding libraries works with CodeBlocks c++. I downloaded the .zip file from http://eigen.tuxfamily.org/index.php?title=Main_Page and extracted the files into my directory. How can I use this library now in my project?

Save answered 13/4, 2016 at 20:30 Comment(2)
Have you searched StackOverflow? For example, use the query "c++ install eigen library code blocks"Marketable
@ThomasMatthews yes, the problem is, when i go to project >> build options >> linker settings tab >> add library, I don't know what file to choose! In the directory where I extracted the files to, there is no .lib filesSave
H
1

It's a template library. You can put it anywhere as long as it's in the path (accessible). Just include the proper headers and it should work. No need to link anything, everything is in the headers.

Hinson answered 13/4, 2016 at 20:36 Comment(2)
Thank you, got it.Save
If you use bash, you can edit .bash_profile in your home directory and add it there, something like PATH=$PATH:$HOME/my_library_path_to_includeHinson
A
5

Add one line of code to your source file where you want to use Eigen.

#include "Eigen/Dense"

Put Eigen (extracted zip file) in a directory where you put your existing working header file.

Amphitropous answered 13/4, 2016 at 20:48 Comment(0)
C
4

Personally I had no idea how to install eigen on code blocks, but those are the steps I made and it worked:

  1. unpack the ZIP into some arbitary folder
  2. go to codeblocks Settings-> complier-> Search Directories-> Add-> enter the address of the folder you chose in (1)-> o.k
  3. declare #include "Eigen/Dense" before the main function.

I learned the steps from here

Cru answered 10/1, 2017 at 17:19 Comment(1)
I am using code blocks 16.01. Your steps worked for me. I just needed to figure out one thing. That there are 3 types of Search Directories - Compiler, Linker, Resource compiler. We have select Compiler tab under Search Directories beforing selecting Add.Melton
S
4

in my radio astronomy project i install Eigen by the following command:

sudo apt-get install libeigen3-dev

my cmake automatically find the eigen header which i used. it is a sample of my header

#include <eigen3/Eigen/Core>
Solfatara answered 7/8, 2018 at 12:25 Comment(0)
M
3

This one was a tricky one for me. I am using Code::Blocks Ver 17.12.

a) I downloaded Eigen 3.3.5 (http://eigen.tuxfamily.org/index.php?title=Main_Page). The zip file downloaded is named as "eigen-eigen-b3f3d4950030"

b) Extracted the file to my project folder.

c) Changed the name of the extracted file from "eigen-eigen-b3f3d4950030" to "Eigen3" (you can choose any name).

d) Inside this folder, you will find other folders such as bench, blas, cmake, debug....

Now you have to add the library files for your project (so that the compiler knows where to look for the required library files).

e) In codeblocks, click on Settings --> Compiler --> Search Directories --> Compiler

Click Add and add the Eigen3 folder (the downloaded and extracted folder which was renamed in previous step 'c'). Once added, click on Linker tab (just beside 'Compiler' tab) and add the same path to Eigen3 folder.

f) Now click on Build Options tab, which is found besides 'Search Directories' tab.

g) Tick the "Explicitly add currently compiling file's directory to compiler search dirs" h) Tick the "Explicitly add project's top-level directory to compile search dirs"

i) Click OK.

Now your build should work and the compiler knows how to search for Eigen libraries.

Any issues, just post it here.

Best wishes

Shre

Mohl answered 7/8, 2018 at 11:42 Comment(0)
H
1

It's a template library. You can put it anywhere as long as it's in the path (accessible). Just include the proper headers and it should work. No need to link anything, everything is in the headers.

Hinson answered 13/4, 2016 at 20:36 Comment(2)
Thank you, got it.Save
If you use bash, you can edit .bash_profile in your home directory and add it there, something like PATH=$PATH:$HOME/my_library_path_to_includeHinson

© 2022 - 2024 — McMap. All rights reserved.