Skip to content

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

Closed

Description

@erikman
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.

Activity

  1. airman00 commented on Dec 7, 2017

    @airman00

    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
  2. hederguerreiro commented on Dec 13, 2017

    @hederguerreiro

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

  3. sergiomarqmoura commented on Dec 28, 2017

    @sergiomarqmoura

    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

  4. alalek commented on Dec 28, 2017

    @alalek
    Member

    Current workaround is disabling IPP (affects x86/x86_64 platforms): add "-DWITH_IPP=OFF" CMake option into build script.

  5. sergiomarqmoura commented on Dec 28, 2017

    @sergiomarqmoura

    @alalek I see, but in practice even with that flag we currently have to remove the x86 and x86_64 ABIs right?

  6. alalek commented on Dec 28, 2017

    @alalek
    Member

    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).

  7. barzto commented on Dec 28, 2017

    @barzto

    @alalek I've got same error while linking against OpenCV binaries I've built with recent NDK (16.1.4479499). So I don't think this is related to old NDK version.

    Doning small google search before encoutering this thread, I've found this NDK issue which may be related:

    android/ndk#556

  8. sergiomarqmoura commented on Dec 29, 2017

    @sergiomarqmoura

    Hey @erikman , I tried to build OpenCV 3.2.0 using NDK r16b (darwin), with the changes you added on the PR for open CV to be able to build with that version, and still getting some issues. To build, I followed these instructions: http://yangchao.me/post/build-opencv-android-sdk/

    Basically I'm getting Specified toolchain "arm-linux-androideabi-4.8" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. . Is there anything else I should change?

    EDIT: after some struggle could pass that point and now it breaks after building for the first api level (android-14) with File "/Users/sergiomoura/repos/temp/opencv/modules/java/generator/gen_java.py", line 1602, in <module> import hdr_parser ImportError: No module named hdr_parser

    Looks like this python module is not found. Would be really awesome that OpenCV could support ndk r16

  9. hannesa2 commented on Dec 29, 2017

    @hannesa2
    Contributor

    To the maintainer of OpenCV: You do a awesome job, but Android platform needs some modernization, please merge any improvement PR to reduce such issues and let the devs concentrate to awesome project they do

  10. sergiomarqmoura commented on Dec 29, 2017

    @sergiomarqmoura

    Also, @erikman did you rebuild OpenCV using your previous NDK but with the "-DWITH_IPP=OFF" on the buildscript or using the newer r16 NDK?


    Yes, the first comment states this:

    Rebuilding OpenCV for Android without IPP support fixes the problem.

  11. alalek commented on Jan 4, 2018

    @alalek
    Member

    @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")
    
  12. erikman commented on Jan 10, 2018

    @erikman
    ContributorAuthor

    @sergiomarquesmoura: my patches for building with r16 are here: #10288, @alalek's solution is nicer though :)

  13. alexandrucaraus commented on Jan 20, 2018

    @alexandrucaraus

    I could build OpenCV only with NDK 15c, the two versions after that 16.0... and 16.1... to current date do not work. Is this an NDK or OpenCV issue?

  14. alalek commented on Jan 20, 2018

    @alalek
    Member

    Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org
    Posts "don't work" with lack of required information are completely useless, consider doing minor investigations and providing related details (including version which you get and what you are doing with samples of exact commands).

    P.S. You should use ndk-16.config with NDK16.

  15. alexandrucaraus commented on Jan 20, 2018

    @alexandrucaraus

    Thanks for the config!

    P.S. "don't work" is short for "I am getting the issue described in the subject", since we are already in this context. I sure can go to OpenCV forum, but I want to talk about this issue :D.

  16. alalek commented on Jan 20, 2018

    @alalek
    Member

    This issue is closed with the link on the patch with fix. It is merged into OpenCV "master" branch, so this issue is resolved.
    It is still unclear that you trying to do (your exact steps). You should understand that we are not able to help (even not to fix, - many problems are related to "configuration issues") if we can't reproduce the issue.

  17. alexandrucaraus commented on Jan 20, 2018

    @alexandrucaraus

    Yep, I saw it's closed.
    So to explain you what I am doing. I was building my application which is using OpenCV for android with NDK15c and all was good and pretty, till I updated to NDK16.0..., after that I got the same error this post was made for, and the version after (NDK16.1...) had the same issue. To solve I downgraded to NDK15c.

    So my question was really easy :), is this related to NDK or to OpenCV, as I was thinking this is an NDK issue. It's okay, you replied to it in the second time, don't need to answer that.

    So next really easy question, all I have to do is to update this file

    /Users/alex/Projects/Android/DocSign/opencv/src/sdk/native/jni/android.toolchain.cmake

    with this changes?

    90cc3f6

  18. alalek commented on Jan 20, 2018

    @alalek
    Member

    I could build OpenCV
    I was building my application which is using OpenCV for android

    They are a different things really.

    You probably have prebuilt OpenCV package without the fix (no releases yet with the fix). So you need to apply some workaronds to hack it. These workarounds depends on how you build your app:

    • do you use modern Android Studio with gradle?
    • is there JNI part of your app? do you use CMake or ndk-build (with .mk files)?

    It is better to use android.toolchain.cmake from Android NDK (instead of OpenCV - like Android Studio does), but it doesn't resolve error from this issue.
    Take a look on workarounds from this comment: #10229 (comment) or from this commit 5f9bb62 .

  19. alexandrucaraus commented on Jan 20, 2018

    @alexandrucaraus

    Yes, I use the prebuilt package for Android (v 3.3.0).

    • Android Studio with gradle ( v 3.0.1).
    • OpenCV only through JNI, don't use the OpenCV java classes.
    • CMake,

    The contents of CMakeLists.txt:

    
    set( OpenCV_DIR "../opencv/src/sdk/native/jni" )
    
    set( CMAKE_VERBOSE_MAKEFILE on )
    
    find_library( log-lib log )
    find_package( OpenCV REQUIRED )
    
    add_library(
                docscan-lib
                SHARED
                src/main/cpp/docscan_java.cpp
                src/main/cpp/docscan.cpp
                src/main/cpp/scanner.cpp
               )
    
    target_link_libraries( docscan-lib ${OpenCV_LIBS} ${log-lib} -ljnigraphics)
    
  20. alalek commented on Jan 20, 2018

    @alalek
    Member

    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")

  21. alexandrucaraus commented on Jan 20, 2018

    @alexandrucaraus

    Yep, works like a charm.
    Thanks a ton!

  22. milly1228 commented on Mar 5, 2018

    @milly1228

    airman00 you save my time , thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions