opencv: OpenCV doesn't link on Android x86/x86_64 with ndk 16.0.4442984 with R_386_GOTOFF error.

System information (version)
  • OpenCV => 3.3.0
  • Operating System / Platform => Android x86/x86_64
  • Compiler => Android toolchain (OpenCV binaries downloaded from github 3.3.0/3.3.1 release, My binary built from Android Studio, ndk-bundle-16.0.4442984 darwin-x86_64-gcc-i686-linux-android-4.9.x)
Detailed description

Can no longer link application for x86 or x86_64, get relocation R_386_GOTOFF against preemptible symbol in symbols from libippiw.a and libippicw.a. Rebuilding OpenCV for Android without IPP support fixes the problem. IPP are only used on x86/x86_64 so this is not a problem for arm builds, but the x86 builds are useful for debugging on HAX accelerated emulator.

Problem appeared after Android ndk upgrade (don’t know my old version). The IPP binaries seems to be a binary only release compiled by Intel so I can’t test rebuilding those libraries, otherwise searching the net suggests that the binaries should be compiled with -fPIC to fix this issue.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Try adding this before “add_library()” (from the comment with workarounds):

set(CMAKE_SHARED_LINKER_FLAGS “${CMAKE_SHARED_LINKER_FLAGS} -Wl,–exclude-libs,libippicv.a -Wl,–exclude-libs,libippiw.a”)

@erikman

Can no longer link application for x86 or x86_64, get relocation R_386_GOTOFF against preemptible symbol in symbols from libippiw.a and libippicw.a

How did you build your application? (ndk-build / cmake from gradle / something else) Do you use OpenCV Java API in your application?


Anyway, there is workaround to build Android application library - don’t use OpenCV static libraries, use libopencv_java3.so instead:

  • CMake: force “java” component
-find_package(OpenCV 3.4 REQUIRED)
+find_package(OpenCV 3.4 REQUIRED java)
  • ndk-build / Android.mk:
-OPENCV_LIB_TYPE:=STATIC
+OPENCV_LIB_TYPE:=SHARED

But probably you will need to load libopencv_java3.so (via System.loadLibrary()) before application native library (not required on modern devices).


Problem is related to visibility of IPPICV symbols in .a files: they should be “hidden” to prevent exporting of these symbols from the .so file. Can be workarounded via these linker flags:

  • add “-Bsymbolic” (or “-Wl,-Bsymbolic”)
  • “–exclude-libs libippicv.a --exclude-libs libippiw.a” (or “-Wl,–exclude-libs,libippicv.a -Wl,–exclude-libs,libippiw.a”)

Something like this:

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a")

I experienced the same issue when I upgraded Android Studio on MacOSX.

Downgrading from NDK16 to NDK14 temporarily solved the issue for me

To downgrade:

  1. Download the older NDK (use 14) from here: https://developer.android.com/ndk/downloads/older_releases.html
  2. Unzip and rename entire NDK folder to “ndk-bundle”
  3. Replace NDK 16 with NDK 14 by replacing the “ndk-bundle” in your Android home folder (for me it was /Library/Android/sdk) with the “ndk-bundle” folder from Step 2

OpenCV binaries downloaded

This package built with Android NDK r10e, so it may just not work with NDK 16 (we don’t test this). You need to rebuilt this package yourself with your target NDK 16 instead.

Mentioned flag doesn’t disable x86/x86_64 libraries (it disables IPP optimizations for x86 only - code may work slower on some workloads).

Any update on this? Have the same issue and downgrading is not really an option because I’m building on an external server with the latest NDK (v16) installed

I had the same issue and your solution @airman00 solved my problem. Thanks!