Embedding Julia in VC++

I am following the instruction here

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

using VS 2019. I am able to build and run up to the “Converting Types” section; but for “Calling Julia Functions”, the build fails with the error

error LNK2001: unresolved external symbol jl_base_module

Has anyone have experience with this? Do I have to modify any of the project include setting at that step?

1 Like

Welcome @algogp

I think you need to tell VS your path to the Julia DLLs. Have a look here

Why isn’t it enough to do all the instructed steps? I have already, as instructed,

  • Added the JULIA_DIR environment variable
  • Added $(JULIA_DIR)\include\julia\ to the Additional Include Directories property in C/C++ | General
  • Added $(JULIA_DIR)\lib to the Additional Library Directories property in Linker | General; and
  • Added libjulia.dll.a;libopenlibm.dll.a; to the list of libraries in Linker | Input

I am unsure here, because I can’t test, but shouldn’t it be just .dll without .a ? This is maybe a typo in the Docs.

Thanks. Removing .a actually makes things worse, in that case the dll cannot even be opened, not just a linkage error anymore. So I guess the doc is correct with that.

I don’t know how to do it manually, but you could try building libcxxwrap-julia, and use its tests as a basis for your embedded code. It also contains some useful helpers to use Julia from C++, but it is not absolutely required of course. Link to the instructions:

I am not sure but I think those are the libraries you compile against and the output will be dependent on those DLL’s. Though I thought things will be linked statically.

I’d also suggest that documentation will include an example for the case the string isn’t trivial.
Namely what if someone wants to run a file?
Also, what about handling packages, Is it possible within Julia embedded?

Interesting to know. Can you elaborate more on how libcxxwrap-julia is used for exposure to C++? Would check it out.

Edit: this line is not immediate clear to me (sorry am not familiar with make file)
“… and configure the Julia_PREFIX option from the built-in CMake support.”
I followed the instruction and in Visual Studio’s CMakeSettings.json page, there is no such name as “Julia_PREFIX”?

OK giving up on this, no idea how to proceed. Thanks everyone.

Sorry, I have been neglecting my notifications a bit. What is meant by that sentence is that in the project CMake settings:

You can either set Julia_PREFIX to the root directory of your Julia installation or (maybe easier) Julia_EXECUTABLE to the full path of your Julia executable.

The most important one is probably JuliaFunction, which simplifies calling Julia functions from C++:

A shot in the dark here: the Embedding Julia page in the doc mentions the use of julia-config.jl on the posix side, but it doesn’t mention an equivalent on the MSVC side. Are we just missing some linker options here or something? It seems like the libraries are being found, so is this an issue of name-mangling or some such thing?