# Standalone app: how to embed julia by calling DLL in c/c++

**URL:** https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088
**Category:** General Usage
**Tags:** embedding
**Created:** [August 1, 2022, 7:44am UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088 "2022-08-01T07:44:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)
#### Post date: [August 1, 2022, 7:44am UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/1 "2022-08-01T07:44:52Z")

</div>

Following instructions from the doc: [Libraries · PackageCompiler](https://julialang.github.io/PackageCompiler.jl/stable/libs.html), I have successfully built julia package to DLL. However, I did not find a way to link the final executable in my Visual Studio C++ project: I got LNK2019 and LNK1120 errors related to unresolved external symbols, because `.lib` files are missing (bug or feature?). Manually generating `.lib` by MSVC `lib.exe` does not work (following [Building libraries on Windows generates DLLs, but not the corresponding import libraries · Issue #687 · JuliaLang/PackageCompiler.jl · GitHub](https://github.com/JuliaLang/PackageCompiler.jl/issues/687)).

How do I compile my package to DLL and link in a C++ project? More specifically, how to configure environments in Visual Studio and deploy in Windows platform?

---

<div class="post-metadata">

### Author: ![uwbanjoman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwbanjoman/32/9998_2.png) [@uwbanjoman](https://discourse.julialang.org/u/uwbanjoman)
#### Post date: [August 13, 2022, 11:51am UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/2 "2022-08-13T11:51:29Z")

</div>

I’m not much of an expert on this but came across following enbedding manual. Perhaps it’s usefull. There’s a piece about linking in it. [Embedding Julia · The Julia Language](https://docs.julialang.org/en/v1/manual/embedding/#High-Level-Embedding-on-Windows-with-Visual-Studio)

---

<div class="post-metadata">

### Author: ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)
#### Post date: [August 13, 2022, 12:29pm UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/3 "2022-08-13T12:29:37Z")

</div>

Thanks for reply :D. Embedding julia in VS is one solution. However, it requires user to install julia environment before running the final app.

I’m trying to find another solution, that is, packaging Julia along with the package in a standalone app. That’s also the reason that I’m using PackageCompiler

---

<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: [August 19, 2022, 7:13pm UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/4 "2022-08-19T19:13:19Z")

</div>

@MatthijsCox published a nice post that might assist you: [Embedding Julia libraries in C++](https://forem.julialang.org/matthijscox/embedding-julia-libraries-in-c-1n12).

---

<div class="post-metadata">

### Author: ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)
#### Post date: [August 20, 2022, 2:06am UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/5 "2022-08-20T02:06:51Z")

</div>

> [@RoyiAvital](#):
>
> @MatthijsCox published a nice post that might assist you: [Embedding Julia libraries in C++](https://forem.julialang.org/matthijscox/embedding-julia-libraries-in-c-1n12).

Thanks. However, it does not solve the problem:

> [@islent](#):
>
> `.lib` files are missing

I also found a similar question (not solved either):

> [@Is it possible for "ccall" to call the shared library created by PackageCompiler.jl?](https://discourse.julialang.org/t/is-it-possible-for-ccall-to-call-the-shared-library-created-by-packagecompiler-jl/84298/50):
>
> Sure, but these are aspirational goals. Here is the current code. Julia does not dynamically launch threads at the moment. They are allocated on startup. They are only shutdown at process exit at the moment.

---

<div class="post-metadata">

### Author: ![MatthijsCox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthijscox/32/42831_2.png) [@MatthijsCox](https://discourse.julialang.org/u/MatthijsCox)
#### Post date: [August 21, 2022, 9:12am UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/6 "2022-08-21T09:12:18Z")

</div>

The Julia library itself is linked against many other libraries, it’s not fully self-contained (this is actually useful sometimes, for example if you don’t want to use llvm.dll).

Are you including the entire folder of files generated by `PackageCompiler.create_library()` ? That folder should be all that’s needed, except for a few system libraries like libc.dll

---

<div class="post-metadata">

### Author: ![islent](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/islent/32/11326_2.png) [@islent](https://discourse.julialang.org/u/islent)
#### Post date: [August 21, 2022, 11:07am UTC](https://discourse.julialang.org/t/standalone-app-how-to-embed-julia-by-calling-dll-in-c-c/85088/7 "2022-08-21T11:07:51Z")

</div>

> [@MatthijsCox](#):
>
> Are you including the entire folder of files generated by `PackageCompiler.create_library()` ?

Yes, I am. In VS project Linker property settings, I appended `%(AdditionalLibraryDirectories)` with the `bin` folder generated by `PackageCompiler.create_library`, and `additional dependencies` with `libjulia.dll.a`.

The problem is that, `PackageCompiler` does not generate a `libMyLib.lib` file along with the `libMyLib.dll`.

I have tried to manually generate the missing `libMyLib.dll` by calling in PowerShell:

```sh
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\Hostx86\x86\lib.exe' /DEF:libMyLib.dll /OUT:libMyLib.lib /MACHINE:X86

```

and the error did not vanish.
