Tried Xcode 16.1 beta today but project is not able to build because of the below error:
Undefined symbols for architecture arm64:
"__mh_execute_header"
I am using unity as a lib in iOS project. And issue is with unity integration
let machineHeader = UnsafeMutablePointer<MachHeader>.allocate(capacity: 1)
machineHeader.pointee = _mh_execute_header
ufw!.setExecuteHeader(machineHeader)
Did some research and found this solution by Apple DTS
But not able to figure out how to solve. Any help is appreciated.
Fixed this issue using below code:
let machineHeader = #dsohandle.assumingMemoryBound(to: MachHeader.self)
ufw!.setExecuteHeader(machineHeader)
Explanation:
While checking the answer from support team, I came across below line:
In Swift you can use #dsohandle to get the start of the Mach-O image regardless of the image type, so this problem goes away. Well, you’ll need to combine that with an unsafeBitCast(_:to:).
#dsohandle: This is a special Swift literal that gives you a handle to the dynamic shared object (DSO) that contains the current code. In other words, it provides access to the starting address of the Mach-O image (the binary that represents the executable or library).
So replacing the direct reference to _mh_execute_header
with a reference that uses #dsohandle
help to solve the compilation error.
Happy coding.