Is it bad to enable Dead Code Stripping?

2020-07-11 10:09发布

My iOS project uses dlsym to dynamically point to an optional C library. Optional as-in the project can run with our without it, it just adds features.

For background info: Detect and use optional external C library at runtime in Objective-C

The problem is, XCode cleans up libraries that are "not used". Using dlsym means there are no direct references to my 3rd party library and XCode removes it.

I thought I found a solution, in "Other Linker Flags" I added -force_load "$(SRCROOT)/my_external.a" which worked great in the simulator. (-all_load works fine too but seemed overkill to me).

The problem is when I moved to a real device, this workaround failed and the library is not loaded (same thing with -all_load).

The only thing that worked was to disable in XCode the feature called Dead Code Stripping.

Question is: is it really bad to disable or recommend my customers to disable this feature? If so, is there a better alternative?

0条回答
登录 后发表回答