1

I have tried quite a lot of suggestions regarding this problem, but none seem to solve my problem.

This is what I am giving as a command:

 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

I am not able to compile com_googlecode_tesseract_android/./src/api/baseapi.cpp It gives me this error:

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

Here is my 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

Here is my 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)

The same error shows up for all 4 headers in baseapi.cpp -

#include <iostream>
#include <string>
#include <iterator>
#include <fstream>

If anyone can help me figure out what is the problem here, it'll be great. Thank you.

PS: I am using NDK r19

Akriti Anand
  • 166
  • 3
  • 17
  • Possible duplicate of [NDK compile warnings on OCR tesseract libraries for android](https://stackoverflow.com/questions/38675799/ndk-compile-warnings-on-ocr-tesseract-libraries-for-android) – emandt Feb 04 '19 at 12:59
  • There's no `arch-arm64` directory in `platforms/android-16`. At least not in the NDK I have installed. It only exists for `android-21` and later platforms. – Michael Feb 04 '19 at 13:01
  • @Michael I have not changed anything besides APP_STL. I directly downloaded it from the website. – Akriti Anand Feb 04 '19 at 14:24
  • @Michael ndk-build knows that and will pull-up to 21 for 64-bit ABIs. – Dan Albert Mar 04 '19 at 23:53
  • 1
    You can simply include `#ifdef __cplusplus #endif ` in all of your header files in which you're facing this issue. `__cplusplus` will be defined for any compilation unit that is being run through the C++ compiler. It works really well. :) – Muhammad Usman Bashir Apr 04 '20 at 07:28

1 Answers1

2

In this situation, your ndk-build does not load the Application.mk file automatically. You must specify it explicitly:

…ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk

Or you can run ndk-build from the tess-two directory (the one above jni). In this case, ndk-build will find both .mk files, and you don't need to specify NDK_PROJECT_PATH:

…ndk-build

The only difference is that the output (obj and libs directories) will be created near, not in the jni directory.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307