Embedding Julia into XCODE in a C++ document, on Big Sur

Hi!

For those who have already embedded Julia into their XCODE project in C++ on a MacOS, preferably an Apple Macbook Pro with the Big Sur operating system… how did you do it?

I’m curious, and eager to learn because… I’ve been stuck all afternoon trying to find an answer that works, and it seems everyone CAN do it, but no one has actually done it yet.

Hi! Help???

I find this Embedding Julia · The Julia Language helpful when embedding julia into C++. My application is on Linux. I guess MacOS should be similar

1 Like

I will test it out and let you know! Not tonight, though– just updated to the newest OS. Big Sur 11.3, which has some changes to improve command line (terminal app) functionality.

1 Like

Did you get anywhere with this? I’m usually using Swift in Xcode, so I’m unfamiliar with linking .dylib files. When I try to run a command line program, I get this:

> dyld[97695]: Library not loaded: @rpath/libjulia.dylib
> Referenced from: [DebugDir]/TestCxx
> Reason: tried: '[DebugDir]/libjulia.dylib' (no such file),     
    '/usr/lib/system/introspection/libjulia.dylib' (no such file), 
    '/usr/local/lib/libjulia.dylib' (no such file), 
    '/usr/lib/libjulia.dylib' (no such file)
For ease of reading, I've replaced the long directory path:
/Users/rob/Library/Developer/Xcode/DerivedData/TestCxx-arxxwbgeuqckzxgqevyqwmdmcuxq/Build/Products/Debug/
with: 
[DebugDir]

There must be some way to set the “rpath” (?) so that it picks up the library. In my build directory there it did copy in the .dylibs, from /Applications/Julia.app/.

And something going on with file names – libjulia.1.7.dylib vs libjulia.dylib.

% pwd
[DebugDir]
% ls
TestCxx			libjulia.1.7.dylib	libopenlibm.3.0.dylib

Those two dylibs are in Xcode as “Embed & Sign”.

I switched off “Enable Hardened Runtime” in the target’s build settings. Then the shared library stuff is easier to get working. I just have “libjulia.1.7.dylib” in my list of libraries, with “Do Not Embed”, and it all works.

I’ll have to revisit the more secure way later, with signing and embedding, if I ever distribute an app with Julia.

I am following this with interest but I can already foresee the problem that I will run into when I hopefully succeed in setting up Xcode as described: How do I call a Julia function from my main program? I have a Julia image analysis function which takes a tiff image as input and returns an array of floats with the results, and I want to call this from Objective C in my case (but information in Swift will probably do too) and catch the array of floats that the function returns.
Any advice on how to accomplish this will be great appreciated, thanks

The docs on embedding has a section on calling Julia functions.

https://docs.julialang.org/en/v1/manual/embedding/#Calling-Julia-Functions

But that doesn’t describe how to load the Julia code from C/C++. You can probably use jl_eval_string, but it looks like jl_load_file_string is better. But that function is not described on in the documentation page.

Dear Robert,

Thanks for a quick reply.

Best regards,

Peter