NDK Clang错误:未定义引用'localeconv'

我试图在Android Studio中构建C ++ NDK库。我有一个名为json的外部库和localeconv上的Clang编译器faild。

json.hpp:11867:错误:未定义引用'localeconv'

locale.h头文件存在于ndk dir sysroot / usr / include中。

我的工具链看起来像这样:

Gradle :(仅显示与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
                    ) 

这里是链接器命令行:

[1/1]链接CXX共享库........ 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: 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-sp束/ platforms / android-19 / arch-arm -Wl, - build-id -Wl, - warn-shared-textrel -Wl, - 致命警告-Wl, - fix- cortex-a8 -Wl, - no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,现在共享-Wl,-soname,libnative-lib.so

完整的错误:

“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引用'localeconv'铿锵++。exe:error:链接器命令失败,退出代码1(使用-v查看调用)ninja:build stopped:子命令失败。 :app:externalNativeBuildDebug FAILED

目标SDK为21.最小SDK为19.NDK版本:15.0.4075724

相同的代码库在使用相同工具链的Visual Studio Android项目中编译得很好。


答案是 - SDK 19的NDK版本没有在STL中实现整个C ++ 11标准。 locale.h头文件有localeconv()方法的存根,但该库没有实现它。实现localeconv()最接近的Android SDK是SDK 21.这在头文件<locale.h>隐含地陈述了。

struct lconv* localeconv(void) __INTRODUCED_IN(21) __VERSIONER_NO_GUARD;

#if __ANDROID_API__ >= 21
locale_t duplocale(locale_t) __INTRODUCED_IN(21);
void freelocale(locale_t) __INTRODUCED_IN(21);
locale_t newlocale(int, const char*, locale_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */

char* setlocale(int, const char*);

#if __ANDROID_API__ >= 21
locale_t uselocale(locale_t) __INTRODUCED_IN(21);
#endif /* __ANDROID_API__ >= 21 */


#define LC_GLOBAL_LOCALE __BIONIC_CAST(reinterpret_cast, locale_t, -1L)

__END_DECLS

#endif /* _LOCALE_H_ */
链接地址: http://www.djcxy.com/p/85541.html

上一篇: NDK Clang error: undefined reference to 'localeconv'

下一篇: Why proc/cpuinfo shows 4 processors only on my galaxy S4