M.A.
M.A.

Reputation: 169

"fatal error: Eigen/Dense: No such file or directory" // Eigen Library

I am doing Android programming using Java-Eclipse Luna on Windows 8.1, also, I am using native environment (C++). I am trying to use the Eigen library in my native code. I am getting a "fatal error: Eigen/Dense: No such file or directory" error which I don't know the reason behind. here is my code:

my .java file:

package com.example.androideignv2;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class AndroidEignV2Activity extends ActionBarActivity {

/** Loading the Native library */
static {
    /** Use either of the following two methods to load the native library*/
    System.loadLibrary("myNativeLibrary");
    //System.load("/data/data/cookbook.chapter2/lib/libNativeRegister.so");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_android_eign_v2);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.android_eign_v2, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

my .cpp native library:

#include <jni.h>
#include <android/log.h>
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <Eigen/Dense>


using namespace Eigen;
using namespace std;

int main() // int argc, char* argv[]
{
  MatrixXd m = MatrixXd::Random(3,3);
  m = (m + MatrixXd::Constant(3,3,1.2)) * 50;
  cout << "m =" << endl << m << endl;
  VectorXd v(3);
  v << 1, 2, 3;
  //cout << "m * v =" << endl << m * v << endl;
}

my Android.mk file:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myNativeLibrary
LOCAL_SRC_FILES := myNativeLibrary.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

my Application.mk file:

APP_ABI := all
APP_STL:=stlport_static 

I included the Eigen library folder in the "Paths and Symbols" by doing: Project / Properties / C/C++ General / Paths and Symbols / includes / and then I browsed to my Eigen library path.

Any hint will be deeply appreciated

Upvotes: 1

Views: 1477

Answers (1)

ph0b
ph0b

Reputation: 14473

You've only added Eigen library include folder to Eclipse paths and symbols.

Referencing this library from your actual NDK build is a different step you have to do. How is your library organized ? Is it already compiled for Android ?

You can reference a 3rd party prebuilt NDK library like this from your Android.mk. Replace the occurences of .so and SHARED by .a and STATIC if what you have is a static prebuilt library instead of a shared one:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := eigen
LOCAL_SRC_FILES := /path/to/eigen/prebuilts/$(TARGET_ARCH_ABI)/libeigen.so
LOCAL_EXPORT_C_INCLUDES := /absolute/path/to/includes
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := myNativeLibrary
LOCAL_SRC_FILES := myNativeLibrary.cpp
LOCAL_SHARED_LIBRARIES := eigen
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

Upvotes: 1

Related Questions