I am trying to build C++ NDK lib inside Android Studio.I have an external lib called json and the Clang compiler faild on localeconv.
json.hpp:11867: error: undefined reference to 'localeconv'
The locale.h header exists and located inside ndk dir sysroot/usr/include.
My toolchain looks like this:
Gradle: (Showing only the part relevant to NDK)
externalNativeBuild {
cmake {
arguments "-DANDROID_PLATFORM_LEVEL=${platformVersion}",
'-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
}
ndk {
abiFilters 'armeabi-v7a'
}
}
Cmake
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -frtti -fexceptions -Wall")
//'native-lib' is the final .so that's packaged into apk
target_link_libraries(native-lib
OPENAL
FREETYPE
android
EGL
${OPENGL_LIB}
log
m
z
atomic
gnustl_static
)
And here is the linker command line:
[1/1] Linking CXX shared library ........\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so FAILED: cmd.exe /C "cd . && D:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi --gcc-toolchain=D:/Android/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=D:/Android/android-sdk/ndk-bundle/sysroot -fPIC -isystem D:/Android/android-sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=19 -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 -Wall -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot D:/Android/android-sdk/ndk-bundle/platforms/android-19/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
The complete error:
"D:/Android/android-sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_static.a" && cd ." D:\XXXXX\XXXXXX\windows....\thirdparty\json/json.hpp:11867: error: undefined reference to 'localeconv' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed. :app:externalNativeBuildDebug FAILED
The target SDK is 21.Minimum SDK is 19.NDK Version: 15.0.4075724
The same code base is compiled fine in Visual Studio Android project which uses the same toolchain.