Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Eigen Library to Android NDK

Tags:

I need to include Eigen library in my Android Studio project to do some linear algebra operations and use some C++ code that I've developed for desktop. I've been looking for information on this topic, but there isn't too much and I'm new on Android NDK. Eigen library doesn't need to be compiled, so I thought It would be easy, but I'm missing something. I've tried to copy the Eigen folder (which have all the includes) into the NDK folder (..\Android\Sdk\ndk-bundle\sysroot\usr\include) where there are other exteral libraries (GLES for example) but Android Studio don't detect it. How can I do it?? Thank you in advance, I really need this.

Edit 1: As you can see here, Eigen lib is included, but when I compile the project there are many errors, and I don't know why. Any ideas?

like image 796
edusan1213 Avatar asked Jan 18 '18 09:01

edusan1213


1 Answers

Finally I reach my objective, and I'm Working with Eigen in Android. If you are triying to use Eigen library in Android, I hope this help you:

  1. Download Eigen library from the official site.
  2. Copy Eigen folder inside the zip you have downloaded in which are all the headers (.h files) of the library and paste it on one folder of your choice in the project. For example, i did it in:

    ../app/src/main/cpp

  3. Edit CMakeLists.txt, adding this line with the path of the Eigen folder inside your project: include_directories(src/main/cpp/Eigen)
  4. Launch the App in a real device (not working on emulator) to load the Eigen header files in it.
  5. Include in your cpp file the Eigen headers and work with them normally. For example:

    #include "Eigen/Dense" void multiply2Matrices(){ Eigen::MatrixXd M(2,2); Eigen::MatrixXd V(2,2); for (int i = 0; i<=1; i++){ for (int j = 0; j<=1; j++){ M(i,j) = 1; V(i,j) = 2; } } Eigen::MatrixXd Result = M*V; }

In my case, I didn't have to compile anything, jus use the header files of official Eigen library

like image 69
edusan1213 Avatar answered Sep 20 '22 12:09

edusan1213