Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link against an executable in objective-c project

Say you want to use functionality or interact with another third-party application. Is it possible to link against an executable in an objective-c project? Can the binary maybe be wrapped inside a framework?

like image 797
Anno2001 Avatar asked Mar 06 '26 02:03

Anno2001


1 Answers

You can use an XCode copy files phase to put an additional executable in with your main one, in Your.app/Contents/MacOS, then (let's say you copied grep) to locate it use [[NSBundle mainBundle] pathForAuxiliaryExecutable:@"grep"].

I do it a little differently, for example I have a Python program one of my apps calls (getting the response in plist format which is nice) and I just have it copied into the My.app/Contents/Resources directory and use [[NSBundle mainBundle] pathForResource:@"myScript" ofType:@"py"] to find it.

Which way you do it is, I suspect, a matter of taste. I think it makes sense to put compiled executables in with the main one, and Python/Perl/whatever in Resources. From there it's just a matter of setting up an NSTask to launch and pipe the aux program's output back into your main executable. More info on that here.

like image 137
K8TIY Avatar answered Mar 07 '26 19:03

K8TIY



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!