链接共享库时选项 -fembed-bitcode 消失
Option -fembed-bitcode disappear when linking shared library
我尝试为 iOS 编译几个开源库作为带有 bitcode 的共享库。我已将标志 -fembed-bitcode
添加到 CFLAGS 和 LDFLAGS 中。编译正常完成,但一些生成的库(例如 curl)中没有位码(我用 otool -l lib.dylib | grep LLVM
检查过)。
我的调查表明,当 dylib 正在链接时,标志 -fembed-bitcode
只是从链接器命令行中消失了,尽管在 Makefile 中在这个地方直接使用了 LDFLAGS。 -fembed-bitcode
如何从 LDFLAGS 中消失?
-fembed-bitcode
标志消失的原因是库使用 libtool 进行链接,默认情况下 strips 未知标志:
When creating a shared library, but not when compiling or creating a
program, libtool drops some flags from the command line provided by
the user. This is done because flags unknown to libtool may interfere
with library creation or require additional support from libtool, and
because omitting flags is usually the conservative choice for a
successful build.
If you encounter flags that you think are useful to pass, as a
work-around you can prepend flags with -Wc, or -Xcompiler to allow
them to be passed through to the compiler driver (see Link mode).
Another possibility is to add flags already to the compiler command at
configure run time:
./configure CC='gcc -m64'
因此,除了 -fembed-bitcode
之外,我还向 LDFLAGS 添加了 -Wc,-fembed-bitcode
标志,并且库使用位码进行编译。
我尝试为 iOS 编译几个开源库作为带有 bitcode 的共享库。我已将标志 -fembed-bitcode
添加到 CFLAGS 和 LDFLAGS 中。编译正常完成,但一些生成的库(例如 curl)中没有位码(我用 otool -l lib.dylib | grep LLVM
检查过)。
我的调查表明,当 dylib 正在链接时,标志 -fembed-bitcode
只是从链接器命令行中消失了,尽管在 Makefile 中在这个地方直接使用了 LDFLAGS。 -fembed-bitcode
如何从 LDFLAGS 中消失?
-fembed-bitcode
标志消失的原因是库使用 libtool 进行链接,默认情况下 strips 未知标志:
When creating a shared library, but not when compiling or creating a program, libtool drops some flags from the command line provided by the user. This is done because flags unknown to libtool may interfere with library creation or require additional support from libtool, and because omitting flags is usually the conservative choice for a successful build.
If you encounter flags that you think are useful to pass, as a work-around you can prepend flags with -Wc, or -Xcompiler to allow them to be passed through to the compiler driver (see Link mode). Another possibility is to add flags already to the compiler command at configure run time:
./configure CC='gcc -m64'
因此,除了 -fembed-bitcode
之外,我还向 LDFLAGS 添加了 -Wc,-fembed-bitcode
标志,并且库使用位码进行编译。