Android.mk-包括OpenCV目录,用于使用NDK进行本机C ++编译 [英] Android.mk - Include OpenCV directory for native C++ compliation with NDK

查看:272
本文介绍了Android.mk-包括OpenCV目录,用于使用NDK进行本机C ++编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NDK将C ++/OpenCV代码导入Android应用.首先,我不得不说我没有编程方面的知识,我只是一个业余开发人员,所以有很多事情我无法管理(特别是编码之外的事情).

I'm importing a C++/OpenCV code to an Android app with NDK. First of all, I have to say that I don't have studies in programming, I'm just an amateur developer, so there're many things that I don't manage (specially, things out of coding).

我在我的C ++/OpenCV代码中使用QtCreator,并在Project.pro中写了这一行:

I use QtCreator for my C++/OpenCV code and I wrote this line in my Project.pro:

INCLUDEPATH += path/to/OpenCV/main/dir #OpenCV-3.1.0
LIBS += -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc

现在,我正在尝试制作一个"Hello World!"应用程序只是为了确保我可以使用我的C ++源代码进行编译.

Now, I'm trying to make a "Hello World!" app only to be sure that I can compile with my C++ sources.

根据 https://developer.android.com/ndk/guides/android_mk .html ,我编写了这个简单的Android.mk文件:

According to https://developer.android.com/ndk/guides/android_mk.html, I wrote this simple Android.mk file:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := myModule
LOCAL_CFLAGS += -I /path/to/OpenCV/main/dir
LOCAL_LDLIBS := -lopencv_core
LOCAL_SRC_FILES := bar.cpp

include $(BUILD_SHARED_LIBRARY)

在bar.cpp中,我有:

In bar.cpp, I have:

#include <opencv2/core/core.hpp>

仅用于检查编译器是否可以找到源.当我尝试使用ndk-build构建我的C ++/OpenCV本机代码时,我得到:

Just for checking that the compiler can found the sources. When I try to build my C++/OpenCV native code using ndk-build, I get:

non-system libraries in linker flags: -lopencv_core
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the current module

我尝试使用LOCAL_STATIC_LIBRARIES和LOCAL_SHARED_LIBRARIES,但没有成功.有什么想法吗?

I tryed to use LOCAL_STATIC_LIBRARIES and LOCAL_SHARED_LIBRARIES, but no succed. Any ideas?

P.S.:

重要的是,我遵循此示例

It's important to say that I compiled a simple Hello world using NDK (wthout including any OpenCV header) following this example https://gist.github.com/gnuanu/252fd406f48f7da2c1c7.

这里有一个帖子 Android.mk:如何包含ffmpeg和Opencv ,但是它没有答案,我无法解决信息...

There is a post here Android.mk: how to include ffmpeg and Opencv, but it has not answers and I can't solve with the info...

推荐答案

首先,下载适用于Android的OpenCV .如果仅使用OpenCV nativ,则必须在Android.mk文件中设置以下内容:

First, download OpenCV for Android. If you are only using OpenCV nativ, you have to set the following in your Android.mk file:

LOCAL_PATH := $(call my-dir)

CVROOT := path_to_opencv/OpenCV-android-sdk/sdk/native/jni

include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=STATIC
include $(CVROOT)/OpenCV.mk

LOCAL_MODULE += myModule

LOCAL_C_INCLUDES += path_to_your_code/bar.h
LOCAL_SRC_FILES += path_to_your_code/bar.cpp 

LOCAL_CFLAGS += -std=c++11 -frtti -fexceptions -fopenmp -w
LOCAL_LDLIBS += -llog -L$(SYSROOT)/usr/lib
LOCAL_LDFLAGS += -fopenmp

include $(BUILD_SHARED_LIBRARY)

很棒的事情是OpenCV提供了OpenCV.mk生成文件,您无需执行任何操作;)

The cool thing is that OpenCV provides the OpenCV.mk makefile and you have not to do anything ;)

这篇关于Android.mk-包括OpenCV目录,用于使用NDK进行本机C ++编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆