xamarin / mobcat

MIT License
43 stars 18 forks source link

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

Open matteopiccioni opened 5 years ago

matteopiccioni commented 5 years ago

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 commented 5 years ago

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.