关于这个问题,我尝试了很多建议,但似乎没有一个能解决我的问题。
这是我给出的命令:
C:\Users\{name}\Desktop\MyApplication\libraries\tess-two-master\tess-two\jni> C:\Users\{name}\AppData\Local\Android\Sdk\android-ndk-r19\ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk
我无法编译 com_googlecode_tesseract_android/./src/api/baseapi.cpp 它给了我这个错误:
Android NDK: WARNING:com_googlecode_tesseract_android/Android.mk:tess: non-system libraries in linker flags: -latomic
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
com_googlecode_tesseract_android/./src/api/baseapi.cpp:45:10: fatal error
'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
make: *** [obj/local/arm64-v8a/objs/tess/./src/api/baseapi.o] Error 1
这是我的 Application.mk
APP_STL:= c++_shared
APP_ABI := armeabi-v7a x86 arm64-v8a x86_64
APP_OPTIM := release
APP_PLATFORM := android-16
APP_CPPFLAGS += -fexceptions -frtti
NDK_TOOLCHAIN_VERSION := clang
这是我的 Android.mk
LOCAL_PATH := $(call my-dir)
TESSERACT_PATH := $(LOCAL_PATH)/com_googlecode_tesseract_android/src
LEPTONICA_PATH := $(LOCAL_PATH)/com_googlecode_leptonica_android/src
LIBJPEG_PATH := $(LOCAL_PATH)/libjpeg
LIBPNG_PATH := $(LOCAL_PATH)/libpng
# Just build the Android.mk files in the subdirs
include $(call all-subdir-makefiles)
baseapi.cpp 中的所有 4 个 header 都出现相同的错误 -
#include <iostream>
#include <string>
#include <iterator>
#include <fstream>
如果有人能帮我弄清楚这里的问题是什么,那就太好了。谢谢。
PS:我使用的是 NDK r19
最佳答案
在这种情况下,您的 ndk-build
不会自动加载 Application.mk 文件。您必须明确指定它:
…ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
或者您可以从 tess-two 目录(jni 上面的目录)运行 ndk-build
。在这种情况下,ndk-build
将找到两个 .mk 文件,您无需指定 NDK_PROJECT_PATH
:
…ndk-build
唯一的区别是输出(obj 和 libs 目录)将在附近创建,而不是在 jni 目录中。
关于安卓NDK : iostream file not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54515598/