Can you force unnecessary code from a static library?

Here's the scenario - I created a custom subclass of NSView, and the implementation is in a static library. The class never refers to the final executable, only from the Interface Builder XML file. Since it is not mentioned, it does not turn on at connection time, and as a result, the class cannot be found at runtime.

Is there a way to get it to be connected, another to thank the link dynamically, or to compile the class directly in the executable itself?

+3
source share
3 answers

You can use the class method classon it, which will be mostly inoperative, but will reference it from your code.

int main(int argc, const char** argv)
{
    [MyClass class]; // There you are! MyClass is now referenced from your code.

    /* ... rest of your main function ... */
}
+1
source

An attempt to use the -all_load or -force_load flags. See comments in the following post:

What does the linker flag -all_load do?

0
source

- ? ..

-1

Source: https://habr.com/ru/post/1754445/


All Articles