Reputation: 176
We know that we could force static libraries to load all object files during linking. This is used for different purposes like including objective c categories into static libraries etc.
My question is, is it possible to force a library to NOT to load all object files when the project uses -ObjC or -all_load flags?
I'm using some clang features (particularly __has_include directive) in order to control importing of some headers, but when -ObjC flag is used, this directive is having no effect, all object files are loaded, so my library do not work properly.
Is there any way to solve or workaround this problem?
Regards,
Upvotes: 1
Views: 425
Reputation: 162712
Is there any way to solve or workaround this problem?
Yes, but it is a fragile and error prone to the point of probably not worth the while. It'll probably be easier to refactor your code to not require partial linkage of your static librar{y,ies}.
It you have a hard reference to each symbol that you require to be loaded, then the linker will resolve the symbol and cause it to be linked into the final executable.
However, as this is not at all a supported or recommended pattern, there may not be a way to directly reference some symbols within the code. As well, there doesn't appear to be a symbol that represents an entire category. You might have to refer to ever method contained within a category individually.
See the nm
command line tool; nm -m library
will dump all symbol information contained within the library.
Upvotes: 2