libtiff.la: $(libtiff_la_OBJECTS) $(libtiff_la_DEPENDENCIES) $(EXTRA_libtiff_la_DEPENDENCIES)
$(AM_V_CCLD)$(libtiff_la_LINK) -rpath $(libdir) $(libtiff_la_OBJECTS) $(libtiff_la_LIBADD) $(LIBS) -Wl,--exclude-libs,libjpeg.a -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
echo "$(AM_V_CCLD)$(libtiff_la_LINK) -rpath $(libdir) $(libtiff_la_OBJECTS) $(libtiff_la_LIBADD) $(LIBS) -Wl,--exclude-libs,libjpeg.a -Wl,-Bstatic -ljpeg2 -Wl,-Bdynamic" > /btif.log
如上代码通过修改-Wl,-Bstatic -ljpeg实现静态依赖libjpeg,但是编译之后仍然是依赖动态库libjpeg.so,打印命令也是正常的。
发现原因:
/bin/bash ../libtool --tag=CC --mode=link /home/debug/1013/cerbero/build/android-ndk-21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target armv7-none-linux-androideabi16 --sysroot /home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm -target armv7-none-linux-androideabi16 --sysroot /home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm -gcc-toolchain /home/debug/1013/cerbero/build/android-ndk-21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -isysroot /home/debug/1013/cerbero/build/android-ndk-21/sysroot -isystem /home/debug/1013/cerbero/build/dist/android_armv7/include -isystem /home/debug/1013/cerbero/build/android-ndk-21/sysroot/usr/include -isystem /home/debug/1013/cerbero/build/android-ndk-21/sysroot/usr/include/arm-linux-androideabi -fno-integrated-as -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fPIC -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -DANDROID -DTCL_PATCH -DPIC -D__ANDROID_API__=16 -D__ARM_ARCH_7A__ -Wa,--noexecstack -Wall -g -Os -Wall -W -no-undefined -version-info 9:0:4 -gcc-toolchain /home/debug/1013/cerbero/build/android-ndk-21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fPIC -no-canonical-prefixes -Wl,-no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -Wl,--warn-shared-textrel -Wl,--exclude-libs,libatomic.a -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libunwind.a -Wl,--fix-cortex-a8 -L/home/debug/1013/cerbero/build/dist/android_armv7/lib -Wl,-z,nocopyreloc -L/home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm/usr/lib -fuse-ld=gold -nostdlib++ -o libtiff.la -rpath /home/debug/1013/cerbero/build/dist/android_armv7/lib tif_aux.lo tif_close.lo tif_codec.lo tif_color.lo tif_compress.lo tif_dir.lo tif_dirinfo.lo tif_dirread.lo tif_dirwrite.lo tif_dumpmode.lo tif_error.lo tif_extension.lo tif_fax3.lo tif_fax3sm.lo tif_flush.lo tif_getimage.lo tif_jbig.lo tif_jpeg.lo tif_jpeg_12.lo tif_luv.lo tif_lzma.lo tif_lzw.lo tif_next.lo tif_ojpeg.lo tif_open.lo tif_packbits.lo tif_pixarlog.lo tif_predict.lo tif_print.lo tif_read.lo tif_strip.lo tif_swab.lo tif_thunder.lo tif_tile.lo tif_version.lo tif_warning.lo tif_webp.lo tif_write.lo tif_zip.lo tif_debugtd.lo tif_unix.lo ../port/libport.la -lz -lm -Wl,--exclude-libs,libjpeg.a -Wl,-Bstatic -ljpeg -Wl,-Bdynamic
libtool: link: rm -fr .libs/libtiff.a .libs/libtiff.la .libs/libtiff.lai
libtool: link: /home/debug/1013/cerbero/build/android-ndk-21/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target armv7-none-linux-androideabi16 --sysroot /home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm -shared -fPIC -DPIC .libs/tif_aux.o .libs/tif_close.o .libs/tif_codec.o .libs/tif_color.o .libs/tif_compress.o .libs/tif_dir.o .libs/tif_dirinfo.o .libs/tif_dirread.o .libs/tif_dirwrite.o .libs/tif_dumpmode.o .libs/tif_error.o .libs/tif_extension.o .libs/tif_fax3.o .libs/tif_fax3sm.o .libs/tif_flush.o .libs/tif_getimage.o .libs/tif_jbig.o .libs/tif_jpeg.o .libs/tif_jpeg_12.o .libs/tif_luv.o .libs/tif_lzma.o .libs/tif_lzw.o .libs/tif_next.o .libs/tif_ojpeg.o .libs/tif_open.o .libs/tif_packbits.o .libs/tif_pixarlog.o .libs/tif_predict.o .libs/tif_print.o .libs/tif_read.o .libs/tif_strip.o .libs/tif_swab.o .libs/tif_thunder.o .libs/tif_tile.o .libs/tif_version.o .libs/tif_warning.o .libs/tif_webp.o .libs/tif_write.o .libs/tif_zip.o .libs/tif_debugtd.o .libs/tif_unix.o -Wl,--whole-archive ../port/.libs/libport.a -Wl,--no-whole-archive -L/home/debug/1013/cerbero/build/dist/android_armv7/lib -L/home/debug/1013/cerbero/build/dist/android_armv7/lib -L/home/debug/1013/cerbero/build/dist/android_armv7/lib -L/home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm/usr/lib /home/debug/1013/cerbero/build/dist/android_armv7/lib/libz.so -lm -ljpeg --sysroot /home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm --sysroot /home/debug/1013/cerbero/build/android-ndk-21/platforms/android-16/arch-arm -gcc-toolchain /home/debug/1013/cerbero/build/android-ndk-21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -isysroot /home/debug/1013/cerbero/build/android-ndk-21/sysroot -fstack-protector-strong -mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -g -Os -gcc-toolchain /home/debug/1013/cerbero/build/android-ndk-21/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -Wl,-no-undefined -Wl,-z -Wl,noexecstack -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,--gc-sections -Wl,--warn-shared-textrel -Wl,--exclude-libs -Wl,libatomic.a -Wl,--exclude-libs -Wl,libgcc.a -Wl,--exclude-libs -Wl,libgcc_real.a -Wl,--exclude-libs -Wl,libunwind.a -Wl,--fix-cortex-a8 -Wl,-z -Wl,nocopyreloc -Wl,--exclude-libs -Wl,libjpeg.a -Wl,-Bstatic -Wl,-Bdynamic -Wl,-soname -Wl,libtiff.so -o .libs/libtiff.so
libtool: link:的可以看到
ome/debug/1013/cerbero/build/dist/android_armv7/lib/libz.so -lm -ljpeg
libs -Wl,libjpeg.a -Wl,-Bstatic -Wl,-Bdynamic -Wl,-soname -Wl,libtiff.so -o .libs/libtiff.so
发现问题了,link没有正常识别-Wl,-Bstatic -ljpeg为一个指令,也是就没有将-ljpeg是为Wl后面的参数,导致问题。
正确的设置方法:
libtiff.la: $(libtiff_la_OBJECTS) $(libtiff_la_DEPENDENCIES) $(EXTRA_libtiff_la_DEPENDENCIES)
$(AM_V_CCLD)$(libtiff_la_LINK) -rpath $(libdir) $(libtiff_la_OBJECTS) $(libtiff_la_LIBADD) $(LIBS) -Wl,--exclude-libs,libjpeg.a -Wl,-Bstatic,-ljpeg -Wl,-Bdynamic
也就是:
-Wl,-Bstatic,ljpeg 或者-Wl,-Bstatic -Wl,ljpeg