Boost-for-Android
Boost-for-Android copied to clipboard
undefined reference to
I build boost using ndk r16 successfully. But when I use it as a static libary I get a error.
Error:FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing '/home/adam/Android/Sdk/cmake/3.6.4111459/bin/cmake' with arguments {--build /home/adam/Gits/wbf/Android-VINS/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
[1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
FAILED: : && /home/adam/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi
--gcc-toolchain=/home/adam/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
--sysroot=/home/adam/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/adam/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideab
i -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
-fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions
-std=gnu++11 -lz -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a
--sysroot /home/adam/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,
-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o ...
/home/adam/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm/usr/lib/liblog.so ../../../../src/main/jniLibs/armeabi-v7a/libopencv_calib3d.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_core.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_features2d.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_flann.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_highgui.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_imgcodecs.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_imgproc.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_ml.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_objdetect.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_photo.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_shape.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_stitching.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_superres.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_ts.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_video.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_videoio.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_videostab.a ../../../../src/main/jniLibs/armeabi-v7a/libceres.a ../../../../src/main/jniLibs/armeabi-v7a/boost/libboost_filesystem-clang-mt-1_65_1.a ../../../../src/main/jniLibs/armeabi-v7a/boost/libboost_program_options-clang-mt-1_65_1.a ../../../../src/main/jniLibs/armeabi-v7a/boost/libboost_system-clang-mt-1_65_1.a -latomic
-lm "/home/adam/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a" && :
./boost/system/system_error.hpp:31: error: undefined reference to 'std::runtime_error::runtime_error(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)'
./boost/system/system_error.hpp:31: error: undefined reference to 'std::runtime_error::runtime_error(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)'
/home/adam/Android/android-ndk-r16/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)'
./boost/system/system_error.hpp:31: error: undefined reference to 'std::runtime_error::runtime_error(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)'
libs/filesystem/src/path.cpp:897: error: undefined reference to 'std::__ndk1::locale::locale(char const*)'
/home/adam/Android/android-ndk-r16/sources/cxx-stl/llvm-libc++/include/__locale:212: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::locale::~locale()'
libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::codecvt<wchar_t, char, mbstate_t>::id'
libs/filesystem/src/path.cpp:897: error: undefined reference to 'std::__ndk1::locale::locale(char const*)'
libs/filesystem/src/path.cpp:947: error: undefined reference to 'std::__ndk1::locale::locale(std::__ndk1::locale const&)'
libs/filesystem/src/path.cpp:897: error: undefined reference to 'std::__ndk1::locale::locale(char const*)'
libs/filesystem/src/path.cpp:948: error: undefined reference to 'std::__ndk1::locale::operator=(std::__ndk1::locale const&)'
libs/filesystem/src/path.cpp:950: error: undefined reference to 'std::__ndk1::locale::~locale()'
libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::locale::~locale()'
libs/filesystem/src/path.cpp:914: error: undefined reference to 'std::__ndk1::locale::~locale()'
/home/adam/Android/android-ndk-r16/sources/cxx-stl/llvm-libc++/include/stdexcept:146: error: undefined reference to 'std::logic_error::logic_error(char const*)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
The gradle configuration is
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "xxx"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-fexceptions", "-frtti", "-std=c++11"
arguments "-DANDROID_TOOLCHAIN=clang"
}
}
ndk {
abiFilters "armeabi-v7a"
//abiFilters "arm64-v8a"
stl "gnustl_shared"
// stl "stlport_shared"
// stl "c++_shared"
//toolchainVersion "4.9"
}
}
Who can help?
I got the same problem, I am using Boost for Android with some library. And found that in gradle android { externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared" }
changing -DANDROID_STL=c++_shared from gnustl_shared will solve the error, however, then another error message would come out
app/src/main/cpp/native-lib.cpp:34: error: undefined reference to 'FaceDetection::GetDetectedFaces(cv::Mat const&, std::__ndk1::vector<FaceBox, std::__ndk1::allocator<FaceBox> >&)'
It looks like that the library I am using is compiled with gnustl_shared which against the Boost for Android library (which required c++_shared), could someone help me out on this?
Could I compile boost for android with gnustl_shared and how? Thanks
https://developer.android.com/ndk/guides/cpp-support.html
Just see that gnustl will be deprecated and removed in a future NDK release. Beginning with NDK r16, you should use libc++ instead
you should use libc++ instead
How do you actually do this?
We specify the following in the gradle file:
ndk {
platformVersion = 21
moduleName = "..."
toolchain = "clang"
ldLibs.add("djinni-support")
ldLibs.add("android")
ldLibs.add("dl")
ldLibs.add("log")
ldLibs.add("z")
cppFlags.add("-frtti")
cppFlags.add("-std=c++14")
cppFlags.add("-fexceptions")
stl "c++_static"
abiFilters.addAll(['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'])
}
Edit:
The important part is the stl
definition which can be either of:
gnustl_shared
, gnustl_static
, c++_shared
or c++_static
Can't find a similar structure in a Qt pipeline :(
Anyway, it is working now with boost-1.68.0 :)
Thanks for the quick reply!
As far as I know, this can't be changed in Qt with an option. The Qt Toolchain you are using must be build with the matching setting. :)
The problem is that I don't know which stl has been used with my NDK android-ndk-r17c. Is there a quick way to know that ?
You can try to ask QT devs to switch to NDK r18, it has only one STL library, so no possibility of mismatched libraries. And they'll need to support it anyway in the future.
On Tue, Oct 9, 2018, 01:02 Gilles Degottex [email protected] wrote:
Qt is using the usual SDK/NDK toolchains, nothing special. The problem is that I don't know which stl has been used with my NDK android-ndk-r17c. Is there a quick way to know that ?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/moritz-wundke/Boost-for-Android/issues/123#issuecomment-427993604, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJewHoFOA04hgnBcYuvrhx1AsUStZ0Zks5ui8t6gaJpZM4SGlPQ .
The Qt prebuild Libraries for Android currently uses NDK 10e if this site is up to date (https://doc.qt.io/qt-5/androidgs.html).
Ok, that's a very good info. Thanks! I'll try a custom rebuild with libc++
Recompiling Qt definitely does the trick.
With configuration:
./configure -opensource -confirm-license -xplatform android-clang --disable-rpath -nomake tests -nomake examples -android-ndk /home/degottex/Research/tools/android-ndk-r17c -android-sdk /home/degottex/Research/tools/android-sdk -android-ndk-host linux-x86_64 -android-arch armeabi-v7a -android-toolchain-version 4.9 -skip qttranslations -skip qtserialport -no-warnings-are-errors
-xplatform android-clang
being the key.