# Embedding Julia in C++: DLL procedure entry point errors

**URL:** <https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 29, 2021, 9:44pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792 "2021-12-29T21:44:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thorgrif](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thorgrif/32/32288_2.png) [@Thorgrif](https://discourse.julialang.org/u/Thorgrif)\
**Post date:** [December 29, 2021, 9:44pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792/1 "2021-12-29T21:44:31Z")

</div>

Good afternoon,

I’ve been trying to follow the basic guide for embedding Julia in C++, and I’m running into a problem when my C++ uses certain standard functions.

![image](https://global.discourse-cdn.com/julialang/original/3X/3/b/3b501a5c44ec8f27f321f0237d41ce8a5c723a29.png)

Here’s a simple bit of test code that causes the problem to occur:

```julia

#include <iostream>
#include <uv.h>
#include <windows.h>
#include <julia.h>
#include <cmath>

int main()
{
    std::cout << "Hello World!\n";

    /* required: setup the Julia context */
    jl_init();

    /* run Julia commands */
    jl_eval_string("print(sqrt(2.0))");

    double a = std::acos(2.0);
    std::cout << a;

    /* strongly recommended: notify Julia that the
         program is about to terminate. this allows
         Julia time to cleanup pending write requests
         and run all finalizers
    */
    jl_atexit_hook(0);
    return 0;
}

```

Edit: Note the std::acos call added in the middle. Without this line, the executable runs and works as expected. The problem arises when I use functions from cmath or other things that appear to have the same function definition as those in the julia dlls. (The linker can’t differentiate?)

Would greatly appreciate any help in resolving this issue. Many thanks!  
Josh

---

<div class="post-metadata">

**Author:** ![Thorgrif](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thorgrif/32/32288_2.png) [@Thorgrif](https://discourse.julialang.org/u/Thorgrif)\
**Post date:** [December 30, 2021, 1:31pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792/2 "2021-12-30T13:31:00Z")

</div>

Still stuck on this. I’ve done some investigating with Dependancy Walker and it seems clear that the executable is expecting the acos function in the julia dlls instead of using the cmath functions.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/1/610ba2662ffd424e01435f1746ea3eeb10711ce0.png)

I’m guessing that the linker doesn’t have a good understanding of the namespacing? Anyone know how to tell the VS2019 linker to prioritize the standard libraries over the additional julia dependancies?

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![Chris\_Green](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris_green/32/32265_2.png) [@Chris\_Green](https://discourse.julialang.org/u/Chris_Green)\
**Post date:** [December 30, 2021, 4:59pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792/3 "2021-12-30T16:59:16Z")

</div>

> [@Thorgrif](#):
>
> Anyone know how to tell the VS2019 linker to prioritize the standard libraries over the additional julia dependancies?

I think just order of libraries on the link line will do this, You might need to explicitly add the standard vc link libraries before the Julia ones to your CMakeLists.txt | vcxproj perhaps?

---

<div class="post-metadata">

**Author:** ![Thorgrif](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thorgrif/32/32288_2.png) [@Thorgrif](https://discourse.julialang.org/u/Thorgrif)\
**Post date:** [January 5, 2022, 1:59pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792/4 "2022-01-05T13:59:54Z")

</div>

I think that I have a solution. The openlibm.dll.a seems like it has the math functions according to ‘dumps’ - but is lacking entry points. A coworker built a .lib based on the dumps output from the dll.a - and that is working like I expected all along.

I’m not sure why the dll.a didn’t have entry points - and wouldn’t expect to need to do this. Seems like there’s a chance that this use case has just not really been done much. It’s perhaps unusual to have any need to use math functions in the c++ as well as the Julia?

If someone has a cleaner way to do this without build our own .lib - I’d welcome the suggestion.

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 5, 2022, 2:49pm UTC](https://discourse.julialang.org/t/embedding-julia-in-c-dll-procedure-entry-point-errors/73792/5 "2022-01-05T14:49:30Z")

</div>

> [@Thorgrif](#):
>
> If someone has a cleaner way to do this without build our own .lib - I’d welcome the suggestion.

It might not fit your needs but the approach in [GitHub - GunnarFarneback/DynamicallyLoadedEmbedding.jl: Embed Julia with dynamical loading of libjulia at runtime.](https://github.com/GunnarFarneback/DynamicallyLoadedEmbedding.jl) is at least very different and less intrusive in the build step.
