NDK: libm static linking

◇◆丶佛笑我妖孽 提交于 2019-12-21 10:20:25

问题


I have a problem during try to compile sources with recent android-9 x86 platform.

Primary question: why static library libm.a and dynamic libm.so are different?

Problem is i've try to compile:

/path/to/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc --sysroot=/path/to/android-ndk-r8/platforms/android-9/arch-x86 -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86/include -L/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/lib -L/path/to/android-ndk-r8/platforms/android-9/arch-x86/usr/lib -static /path/to/gcc_4_4_6_release/gcc/testsuite/gcc.dg/complex-5.c -std=c99 -O -ffloat-store -o ./complex-5.exe -lm

but I have undefined reference:

/tmp/cc78CsCp.o: In function main': complex-5.c:(.text+0x1a2): undefined reference tofeclearexcept' complex-5.c:(.text+0x1b3): undefined reference to `fetestexcept' collect2: ld returned 1 exit status

pwd: /path/to/android-ndk-r8/platforms/android-9/arch-x86/usr/lib

ls libm* libm.a libm.so

It exists, but if we look with nm for feclearexcept, it isn't present within static library.

Ok, just try to remove -static flag.

/path/to/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc --sysroot=/path/to/android-ndk-r8/platforms/android-9/arch-x86 -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86/include -L/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/lib -L/path/to/android-ndk-r8/platforms/android-9/arch-x86/usr/lib /path/to/gcc_4_4_6_release/gcc/testsuite/gcc.dg/complex-5.c -std=c99 -O -ffloat-store -o ./complex-5.exe -lm

Ok. That the question: why they are differ? I need static linkage, I don't want to force usage of dynamic linkage with -Wl,-Bdynamic -lm. By the way: regular linux libm.a and libm.so contains similar list of functions.

来源:https://stackoverflow.com/questions/11028844/ndk-libm-static-linking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!