Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Option -fembed-bitcode disappear when linking shared library

I try to compile several open-source libraries for iOS as shared libraries with bitcode. I've added flag -fembed-bitcode into CFLAGS and LDFLAGS. Compilation completes normally but some of resulting libraries (curl for example) has no bitcode in them (I've checked it with otool -l lib.dylib | grep LLVM).

My investigation shows that flag -fembed-bitcode simply disappears from linker command line when dylib is linking though in Makefile there is direct usage of LDFLAGS in this place. How -fembed-bitcode can be dissapear from LDFLAGS?

like image 538
Alexander Ushakov Avatar asked Aug 10 '26 01:08

Alexander Ushakov


1 Answers

The reason for -fembed-bitcode flag disappearing is that library use libtool for linking and it strips unknown flags by default:

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'

So I've just add -Wc,-fembed-bitcode flag to LDFLAGS in addition to -fembed-bitcode and library compiles with bitcode.

like image 84
Alexander Ushakov Avatar answered Aug 13 '26 00:08

Alexander Ushakov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!