mobcat icon indicating copy to clipboard operation
mobcat copied to clipboard

Android: error '...relocation R_386_GOTOFF...' while compiling native

Open matteopiccioni opened this issue 5 years ago • 1 comments

Hello, first of all thanks for your great tutorial I have a native library to compile for Android and iOS. In iOS I dont have problems, but for Android I have that when I call this line:

$CXX -shared -static-libstdc++ -o ${PWD}/sourceFilesAndroid/lib${LibraryName}.so ${PWD}/sourceFilesAndroid/*.o

the script return me this error: /Users/user/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: /Progetti/_InimSDK/PrimeAPIMobile/PrimeFuncsLib/tmp/sourceFilesAndroid/seriale.o: relocation R_386_GOTOFF against preemptible symbol app_data cannot be used when making a shared object

Here I read that it shoud be a problem on the latest ndk

Anyway I add -fPIC for cpp compiling and now the so files are generated

    for i2 in $LibPath/*.cpp; do
        ShortName="${i2##*/}"
        OutputName="${ShortName/cpp/o}"
        $CXX -c $i2  -std=c++0x  -fPIC -D __MYblabla__ -o ${PWD}/sourceFilesAndroid/$OutputName
    done

    $CXX -shared -static-libstdc++ -o ${PWD}/sourceFilesAndroid/lib${LibraryName}.so ${PWD}/sourceFilesAndroid/*.o

Hope it can helps other users Thanks

matteopiccioni avatar Jul 05 '19 07:07 matteopiccioni