# Embedding Julia in VC++

**URL:** <https://discourse.julialang.org/t/embedding-julia-in-vc/36939>\
**Category:** General Usage\
**Created:** [April 3, 2020, 6:18am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939 "2020-04-03T06:18:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![algogp](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@algogp](https://discourse.julialang.org/u/algogp)\
**Post date:** [April 3, 2020, 6:18am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/1 "2020-04-03T06:18:10Z")

</div>

I am following the instruction here

[https://docs.julialang.org/en/v1/manual/embedding/index.html#Calling-Julia-Functions-1](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?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 3, 2020, 8:57am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/2 "2020-04-03T08:57:11Z")

</div>

Welcome @algogp

I think you need to tell VS your path to the Julia DLLs. Have a look here  
[https://stackoverflow.com/questions/2119539/how-do-i-set-the-path-to-a-dll-file-in-visual-studio](https://stackoverflow.com/questions/2119539/how-do-i-set-the-path-to-a-dll-file-in-visual-studio)

---

<div class="post-metadata">

**Author:** ![algogp](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@algogp](https://discourse.julialang.org/u/algogp)\
**Post date:** [April 3, 2020, 9:04am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/3 "2020-04-03T09:04:33Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [April 3, 2020, 9:22am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/4 "2020-04-03T09:22:47Z")

</div>

> [@algogp](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![algogp](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@algogp](https://discourse.julialang.org/u/algogp)\
**Post date:** [April 3, 2020, 9:29am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/5 "2020-04-03T09:29:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [April 3, 2020, 9:37am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/6 "2020-04-03T09:37:22Z")

</div>

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:

> **[GitHub - JuliaInterop/libcxxwrap-julia: C++ library for backing CxxWrap.jl](https://github.com/JuliaInterop/libcxxwrap-julia#building-on-windows)**
>
> C++ library for backing CxxWrap.jl. Contribute to JuliaInterop/libcxxwrap-julia development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)\
**Post date:** [April 3, 2020, 11:02am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/7 "2020-04-03T11:02:33Z")

</div>

> [@oheil](#):
>
> > [@algogp](#):
> >
> > 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.

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?

---

<div class="post-metadata">

**Author:** ![algogp](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@algogp](https://discourse.julialang.org/u/algogp)\
**Post date:** [April 4, 2020, 9:00am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/8 "2020-04-04T09:00:21Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![algogp](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@algogp](https://discourse.julialang.org/u/algogp)\
**Post date:** [April 6, 2020, 4:39am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/9 "2020-04-06T04:39:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [April 7, 2020, 9:05pm UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/10 "2020-04-07T21:05:50Z")

</div>

> [@algogp](#):
>
> 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”?

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

> **[Customize CMake build settings in Visual Studio](https://learn.microsoft.com/en-us/cpp/build/customize-cmake-settings?view=msvc-170&viewFallbackFrom=vs-2019)**
>
> Learn more about: Customize CMake build 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.

> [@algogp](#):
>
> Can you elaborate more on how libcxxwrap-julia is used for exposure to C++?

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

> **[GitHub - JuliaInterop/CxxWrap.jl: Package to make C++ libraries available in...](https://github.com/JuliaInterop/CxxWrap.jl#direct-call-to-julia)**
>
> Package to make C++ libraries available in Julia. Contribute to JuliaInterop/CxxWrap.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tuckermcclure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tuckermcclure/32/1187_2.png) [@tuckermcclure](https://discourse.julialang.org/u/tuckermcclure)\
**Post date:** [April 8, 2020, 12:38am UTC](https://discourse.julialang.org/t/embedding-julia-in-vc/36939/11 "2020-04-08T00:38:47Z")

</div>

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?
