Incorporate an executable file

I have a code written in C++ that I want to incorporate into my Xcode project. From that code, I have also created an executable (.exe) file. How would I link the executable file with my Xcode project, in such a way that I am able to send parameters from the Xcode project to the funcitons in my .exe file? I have been able to wrap my C++ code in Objective-C and incorporate it that way, however it would be simplest for me if I could find a way to get an executable file to run. So far I have tried to edit the product scheme (product -> scheme->edit scheme->info) and add my .exe file to the Executable field, but that has done nothing except give me the error "Found an unexpected Mach-O header code: 0x905a4d". I have also tried to add the .exe file to the Linking section of the project Build Settings, and have not had any success there either. I would really appreciate step-bystep instructions as to how I could accomplish this.


My Xcode project is written in Swift and for iOS.


Thank you.

Replies

I'm not sure what you are trying to do. If you can wrap the C++ code in an Objective-C/C++ wrapper, and call into that way from Swift, that seems the most straightforward manner to use you code in your Swift project. If you want to go into the separate process architecture with the C++-based executable, assuming the Swift code is providing the user interface, it will become much more complicated with having to use XPC to communicate between the Swift and C++ executables, consider sandboxing issues, process de-activation and background processes, and a host of other considerations, especially on iOS.


I am also unclear about whether the executable actually runs. I'm assuming you've built a Darwin(Mach-O) executable. However, if your use of the (.exe) suffix actually indicates that the executable was built on Windows, then the error message makes a lot of sense. You trying to run a Windows executable on a Darwin/Mach-O system. Does not work, as you've found out! Executable formats, conventions, library factors, and a host of other issues prevent this from happening. From a Darwin point of view, your Windows executable is just a binary file, with no signficance whatsoever with regace to executing. Compiling and linking everything using Xcode and Apple's compilers and linkers is the best way of proceeding