Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

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

Open
matteopiccioni opened this issue Jul 5, 2019 · 1 comment

Comments

@matteopiccioni
Copy link

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

@mikeparker104
Copy link
Contributor

Thanks for sharing @matteopiccioni and it's great to hear the tutorial was helpful to you. I'll keep the issue open until I can fully investigate and update the tutorial accordingly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants