1

i get many undefined reference errors when i code opencv under android NDK, such as:

system.cpp:(.text.unlikely._ZNSs4_Rep10_M_disposeERKSaIcE.part.5+0x1c): undefined reference to `std::string::_Rep::_M_destroy(std::allocator const&)'

G:/AndroidProjects/SprayingPrjJNI/app/src/main/cpp/../jniLibs/arm64-v8a/libopencv_core.a(system.cpp.o): In function `void std::_Destroy(std::string*, std::string*, std::allocator&) [clone .isra.88]':

system.cpp:(.text.unlikely._ZSt8_DestroyIPSsSsEvT_S1_RSaIT0_E.isra.88+0x18): undefined reference to `std::string::_Rep::_S_empty_rep_storage'

system.cpp:(.text.unlikely._ZSt8_DestroyIPSsSsEvT_S1_RSaIT0_E.isra.88+0x2c): undefined reference to `std::string::_Rep::_S_empty_rep_storage'

..................

i really dont know how to fix these errors, please help me, thanks

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Hi, the issue may be tightly related to the versions of NDK and OpenCV that you have chosen to work with. Please update your question with the version info for both. – Alex Cohn Mar 12 '19 at 09:35
  • You could also have a look at *[my recent answer](https://stackoverflow.com/a/54980053/192373)* that provides an easy start to working with OpenCV through NDK. It is tuned for **CMake** build system, so if you prefer **ndk-build**, feel free to ask for further instructions. – Alex Cohn Mar 12 '19 at 09:38
  • thank you very much for your comments, NDK version is 19.1,and openCV version is 3.4.5 – Solid Snake Mar 13 '19 at 01:29

1 Answers1

3

See NDK - problems after GNUSTL has been removed from the NDK (revision r18).

But if you don't have very strong reasons to stay with the old version of OpenCV, the easiest approach is to switch to prebuilt OpenCV 4.01 which is compatible with NDK r19.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • thanks for your suggestion, however, when i try to switch to OpenCV 4.0.1, i get a new problem: when i import module opencvpath\sdk\java to my project , the module name in "import module from source" dialog is ":java", not a name as "openCVLibraryXXX", what is the problem? – Solid Snake Mar 14 '19 at 08:45
  • additionally, my android IDE is android studio, thank you verymuch – Solid Snake Mar 14 '19 at 08:51
  • or does it mean it is not necessary to import java module when i use NDK? – Solid Snake Mar 14 '19 at 09:04
  • You can use OpenCV as Java library, or as native library, or both. The approach I described I the linked answer speaks about the second option. For Java, I edit my gradle files manually. – Alex Cohn Mar 14 '19 at 20:53
  • thank you very much, however I also feel difficult to finish the project configuration. would you like to email me a opencv 4.0.1 project framework to learn under android studio 3.3.2? i would very appreciate if you could. my email is :mtlyab@gmail.com, thanks a lot! – Solid Snake Mar 15 '19 at 04:06
  • I don't really understand your request. What's wrong with your project configuration? – Alex Cohn Mar 15 '19 at 08:53
  • I don't really understand your request. What's wrong with your project configuration? – Alex Cohn Mar 15 '19 at 08:54