Undefined symbol: __mh_execute_header

I am building a unit test. The target of this unit test is my framework. My framework linked with couple of static libraries. When the test is running in simulator with host app it works fine. But when I try to test without host app I get following error from linker. PS: My test's xcconfig is similar to the host app's, and I can build the host app successfully.

Undefined symbols for architecture arm64: "__mh_execute_header", referenced from: So what is __mh_execute_header and what framework/library it is defined in? Thanks for any help!

Replies

__mh_execute_header is a symbol inserted by the linker to represent the beginning of the Mach-O image in an executable. It’s only present in an executable. When you build another Mach-O type, you get a different symbol. For example, for a bundle the symbol is __mh_bundle_header and for a dynamic library it’s __mh_dylib_header. You can learn more about this from the comments in <mach-o/ldsyms.h>.

It seems like something in your code is referencing __mh_execute_header on the assumption that it’s going to be linked into an executable. In your standalone unit test it’s not — it’s linked into your test bundle instead — and thus the symbol isn’t defined.

IMPORTANT When you go hunting for this, remember that the first leading underscore puts this in the C ‘namespace’. So, if you’re searching C (or Swift, I guess) code for this, you need to look for _mh_execute_header.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"