2

I am trying to create .so files using Cygwin for my Android ndk application. But Cygwin terminal is showing following errors.

$ /cygdrive/c/native_work/android-ndk-r8b/ndk-build
Cygwin         : Generating dependency file converter script
Compile++ thumb  : main <= main.cpp
In file included from jni/NotePaperDetector.hpp:4:0,
             from jni/main.cpp:1:
jni/NoteLocation.hpp:4:30: fatal error: opencv2/opencv.hpp: No such file or directory
compilation terminated.
/cygdrive/c/native_work/android-ndk-r8b/build/core/build-binary.mk:255: recipe for         target `obj/local/armeabi/objs/main  /main.o' failed
make: *** [obj/local/armeabi/objs/main/main.o] Error 1

I have the following files in my jni folder -

NotePaperDetector.hpp 
NotePaperDetector.cpp 
NoteDescription.hpp 
NoteDescription.cpp 
NoteLocation.hpp 
NoteLocation.cpp 
ImageUtils.hpp
ImageUtils.cpp
MarkerCandidate.hpp
MarkerCandidate.cpp
main.cpp

Android.mk file is -

  LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

# Here we give our module name and source file(s)
LOCAL_MODULE    := main
LOCAL_SRC_FILES := main.cpp

include $(BUILD_SHARED_LIBRARY)
Pie
  • 262
  • 2
  • 10
  • LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Here we give our module name and source file(s) LOCAL_MODULE := main LOCAL_SRC_FILES := main.cpp include $(BUILD_SHARED_LIBRARY) – Pie Sep 25 '12 at 09:34
  • see this http://stackoverflow.com/questions/10106965/how-to-link-any-libarary-in-ndk-application – Jeegar Patel Sep 25 '12 at 09:41

1 Answers1

2

The system cannot find path to OpenCV installation. You need to add LOCAL_C_INCLUDES variable to Android.mk pointing to the OpenCV folder, i.e:

LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../opencv
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • Note that `LOCAL_C_INCLUDES` lists _directories_ relative to the current directory of **make**, usually the Android project directory, with the `ApplicationManifest.mk` file, while the `LOCAL_SRC_FILES` lists _files_ relative to the `LOCAL_PATH`, usually named `jni`. You can also use absolute paths in `LOCAL_C_INCLUDES`, e.g. `/cygdrive/c/downloads/opencv` – Alex Cohn Sep 25 '12 at 12:35
  • You cannot use /cygdrive/ if you are developing in a Cygwin-less environment on Windows. – Sergey K. Sep 25 '12 at 12:42
  • You are right, and NDK-r8b can luckily be used without Cygwin. I believe that with or without Cygwin, `LOCAL_C_INCLUDES += c:/downloads/opencv` will work. But the question explicitly speaks about Cygwin environment, that's why I formatted the path this way. – Alex Cohn Sep 25 '12 at 13:18
  • Sure, but there is a portable way of using relative paths with many ".." – Sergey K. Sep 25 '12 at 16:10
  • Actually I have to use Open CV in my application with some native code to Image Recognization through Camera. Can you please suggest how I need to add that library and create make file. – Pie Sep 26 '12 at 06:59
  • Here you go: http://stackoverflow.com/questions/10106965/how-to-link-any-libarary-in-ndk-application – Sergey K. Sep 26 '12 at 07:05
  • **Meta-discussion** [@Sergey K.](http://stackoverflow.com/users/1065190/sergey-k"): _there is a portable way of using relative paths with many ".."_ - I beg to differ. The problem is that in `Android.mk` we don't have a guaranteed _current directory_. It may be included in a project (or in different projects) in various ways, leading to inconsistent relative paths. Luckily, `LOCAL_PATH` is guaranteed. Therefore, I prefer setting `LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../something` instead of `LOCAL_C_INCLUDES += ../../something`, even though usually these two are equivalent. – Alex Cohn Sep 27 '12 at 09:13
  • We can use ``LOCAL_PATH := $(call my-dir)`` to get the directory. I have updated the answer. – Sergey K. Sep 27 '12 at 09:17