I have a symbol that is being referenced in an Xcode dynamic library target, but it is not defined there. I NEED this symbol to be undefined. This is because it will be compiled differently in each process that includes it (based upon some compile time defines).
The dynamic library target in Xcode that fails to link because it contains a reference to this symbol (which is not unexpected), but I know that the symbol will be available at run time. I will be compiling this function into each target that the common library is linked to.
I am trying to get the linker to mark this particular symbol for dynamic lookup at run time.
I have been able to get it to link if I specify "-undefined dynamic_lookup" as one of the "Other Linker Flags" in my Xcode project. The problem is that I don't want to go that far. I know that only 1 symbol is supposed to be undefined. I want all the rest of the symbols to generate errors if they are left as undefined (I want to avoid a run time missing symbol error basically).
I found a ld linker option that seems like it should do what I need (from ld man page):
-U symbol_name
Specified that it is ok for symbol_name to have no definition. With -two_levelnamespace, the resulting symbol will be marked dynamic_lookup which means dyld will search all loaded images.
However, I cannot seem to get it to work. Whenever I specify "-U symbolName" or "-UsymbolName" in the "Other Linker Flags" I am still greeted with this linker error:
Undefined symbols for architecture x86_64:
"_symbolName", referenced from: <various object files>
Am I using -U incorrectly perhaps? Is it not really the option I need, or is it just not working like it is supposed too?
Setting -Wl,-undefined,dynamic_lookup
is dangerous, since it disables all undefined warning.
Use -Wl,-U,symbol_name
in OTHER_LDFLAGS
to disable warnings for a single symbol.
In Xcode:
Other Linker Flags
Set -Wl,-undefined,dynamic_lookup
to OTHER_LDFLAGS
.
Link: Xcode clang link: Build Dynamic Framework (or dylib) not embed dependencies
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With