# Using a C++ library with Julia 1.\*.\*

**URL:** <https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573>\
**Category:** New to Julia\
**Tags:** cxx\
**Created:** [November 15, 2018, 7:26pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573 "2018-11-15T19:26:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luis\_de\_Sousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luis_de_sousa/32/5503_2.png) [@Luis\_de\_Sousa](https://discourse.julialang.org/u/Luis_de_Sousa)\
**Post date:** [November 15, 2018, 7:26pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/1 "2018-11-15T19:26:05Z")

</div>

In the index page of [julialang.org](http://julialang.org) is stated:

> you can easily use libraries from [Python](https://github.com/JuliaPy/PyCall.jl), [R](https://github.com/JuliaInterop/RCall.jl), [C/Fortran](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#Calling-C-and-Fortran-Code-1), [C++](https://github.com/Keno/Cxx.jl), and [Java](https://github.com/JuliaInterop/JavaCall.jl)

The C++ bit links to a library called Cxx that [fails to install on Julia 1.0.0 and 1.0.2](https://github.com/Keno/Cxx.jl/issues/393) and seems to [no longer be maintained](https://github.com/Keno/Cxx.jl/issues/390).

Is there any other way of using a C++ library with Julia?

Thank you.

P.S.: the [julialang.org](http://julialang.org) main page might need updating.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 15, 2018, 7:27pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/2 "2018-11-15T19:27:51Z")

</div>

Take a look at [GitHub - JuliaInterop/CxxWrap.jl: Package to make C++ libraries available in Julia](https://github.com/JuliaInterop/CxxWrap.jl).

---

<div class="post-metadata">

**Author:** ![Luis\_de\_Sousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luis_de_sousa/32/5503_2.png) [@Luis\_de\_Sousa](https://discourse.julialang.org/u/Luis_de_Sousa)\
**Post date:** [November 15, 2018, 7:38pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/3 "2018-11-15T19:38:05Z")

</div>

Hi Kristoffer, thank you for the reply. I have not given it a try, but CxxWrap looks like overkill. If it is necessary to compile extra shared libraries, and in turn load them in Julia, then it is possibly easier to simply programme everything in C++.

Cheers.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 15, 2018, 7:48pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/4 "2018-11-15T19:48:17Z")

</div>

> [@Luis\_de\_Sousa](#):
>
> If it is necessary to compile extra shared libraries, and in turn load them in Julia, then it is possibly easier to simply programme everything in C++.

I mean, that totally depends on what you are planning on doing. But sure, there is always some overhead with interlanguage programming and you have to evaluate if it makes sense based on your situation.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [November 16, 2018, 1:52am UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/5 "2018-11-16T01:52:44Z")

</div>

You could use extern C, compile into a shared library, and then `ccall` the `C++` functions exactly as you would C/Fortran code.

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [November 16, 2018, 9:59am UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/6 "2018-11-16T09:59:50Z")

</div>

I argue that Cxx.jl is (had been) such an awesome thing that the other solutions, while very valid, are not on par with it, at least for quick but intricate usage of existing C++ libraries.

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [November 16, 2018, 12:23pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/7 "2018-11-16T12:23:43Z")

</div>

Some company who needs Cxx.jl should pay Juliacomputing to get it working again.

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 16, 2018, 3:43pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/8 "2018-11-16T15:43:07Z")

</div>

Redefining `private` as `public` , [for example](https://github.com/Keno/Cxx.jl/blob/06cfb1fb6698680775e3f91252782ca66ee62c67/src/CxxREPL/replpane.jl#L68):

```java
    #define private public
    #include "clang/Parse/Parser.h"
    #undef private

```

is sin against good programming practice where punishment is (at least) hardly sustainable package.

---

<div class="post-metadata">

**Author:** ![cdsousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdsousa/32/215553_2.png) [@cdsousa](https://discourse.julialang.org/u/cdsousa)\
**Post date:** [November 16, 2018, 3:58pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/9 "2018-11-16T15:58:41Z")

</div>

I can’t help but smile every time I see those lines 😄

(edit: I say this with all the respect to Keno. I smile due to how cleverly but awfully one can hack C/C++ preparser.)

---

<div class="post-metadata">

**Author:** ![Luis\_de\_Sousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luis_de_sousa/32/5503_2.png) [@Luis\_de\_Sousa](https://discourse.julialang.org/u/Luis_de_Sousa)\
**Post date:** [November 19, 2018, 6:49pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/10 "2018-11-19T18:49:53Z")

</div>

If Cxx is so bad and unsustainable, then why is it linked from the [julialang.org](http://julialang.org) main page with the claim that Julia integrates with C++?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 19, 2018, 6:55pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/11 "2018-11-19T18:55:54Z")

</div>

> [@Luis\_de\_Sousa](#):
>
> If Cxx is so bad and unsustainable,

There are some people here on the forums that unfortunately seem to try their best to inject poison into most of the thread they comment in. Personally, I think it is best to ignore such people.

From what I have heard, Cxx is in progress of getting updated so I don’t think there is a need for a great deal of worry.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 19, 2018, 6:57pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/12 "2018-11-19T18:57:15Z")

</div>

It’s not unsustainable, it just hasn’t been updated yet and there are [other work items](https://discourse.julialang.org/t/compiler-work-priorities/17623) that are more important for the compiler team to work on at the moment. You can use CxxWrap as well, which already supports Julia 1.0.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 19, 2018, 7:00pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/13 "2018-11-19T19:00:34Z")

</div>

> [@Luis\_de\_Sousa](#):
>
> If Cxx is so bad and unsustainable,

> [@kristoffer.carlsson](#):
>
> There are some people here on the forums that unfortunately seem to try their best to inject poison into most of the thread they comment in.

I have to agree that @Luis_de_Sousa’s comment seems really unnecessarily unpleasant and toxic. This is the kind of thing that makes supporting open source projects so very unpleasant sometimes. Please reconsider your tone and attitude about the projects that you use for free.

---

<div class="post-metadata">

**Author:** ![Luis\_de\_Sousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luis_de_sousa/32/5503_2.png) [@Luis\_de\_Sousa](https://discourse.julialang.org/u/Luis_de_Sousa)\
**Post date:** [November 19, 2018, 7:25pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/14 "2018-11-19T19:25:06Z")

</div>

That would be great news. Any resource that could be referenced on that? Or where I could follow progress? Over at GitHub there are a couple of issues open on maintenance, but none has been answered.

Cheers.

---

<div class="post-metadata">

**Author:** ![Luis\_de\_Sousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luis_de_sousa/32/5503_2.png) [@Luis\_de\_Sousa](https://discourse.julialang.org/u/Luis_de_Sousa)\
**Post date:** [November 19, 2018, 7:28pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/15 "2018-11-19T19:28:56Z")

</div>

Interesting, I understood this package was put together by a third party, but is it now abridged by the core developers? This would explain why it is so quiet over at GitHub. Can you clarify?

Thank you.

---

<div class="post-metadata">

**Author:** ![Luis\_de\_Sousa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luis_de_sousa/32/5503_2.png) [@Luis\_de\_Sousa](https://discourse.julialang.org/u/Luis_de_Sousa)\
**Post date:** [November 19, 2018, 7:32pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/16 "2018-11-19T19:32:03Z")

</div>

> [@StefanKarpinski](#):
>
> I have to agree that @Luis_de_Sousa’s comment seems really unnecessarily unpleasant and toxic

Please read the thread again, the “poison” remark was not directed at me. I fail to see where have I been unpleasant, let alone toxic.

Cheers.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 19, 2018, 7:39pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/17 "2018-11-19T19:39:58Z")

</div>

@keno developed and maintains Cxx. He is one of the core members of Julia’s compiler team and a co-founders of Julia Computing. He’s fairly busy these days, working on, among other things: [Julia’s TPU support](https://twitter.com/jeffdean/status/1054951415339192321), getting Julia’s debugger working on Julia 1.0, and eventually getting Cxx working on Julia 1.0, not to mention being on the [Forbes 30 under 30 list](https://www.forbes.com/profile/keno-fischer/). There are other people—not that many, however, and they would need to spend a lot more time learning things—who could potentially do some of this work but they’re also busy working on other things, which is why I made a post giving a rough sense of the priorities of the compiler team.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 19, 2018, 7:43pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/18 "2018-11-19T19:43:05Z")

</div>

My apologies if you didn’t mean it that way, and yes, I see that you were not the one who started talking about Cxx being “unmaintainable” and criticizing the way it works (which is fairly unavoidable since it needs to be able to access the private members of C++ data structures).

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 19, 2018, 9:32pm UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/19 "2018-11-19T21:32:41Z")

</div>

> [@Luis\_de\_Sousa](#):
>
> If Cxx is so bad […]

I don’t see Cxx.jl as bad I see it as [state of art](https://discourse.julialang.org/t/what-package-s-are-state-of-the-art-or-attract-you-to-julia-and-make-you-stay-there-not-easily-replicateable-in-e-g-python-r-matlab/11294/13)!

> [@StefanKarpinski](#):
>
> There are other people—not that many, however, and they would need to spend a lot more time learning things—who could potentially do some of this work

As we could see - not easy maintainable.

> [@StefanKarpinski](#):
>
> I see that you were not the one who started talking about Cxx being “unmaintainable” and criticizing the way it works (which is fairly unavoidable since it needs to be able to access the private members of C++ data structures).

Unmaintanability was [hyperbole](https://en.wikipedia.org/wiki/Hyperbole) about sin and punishment. But one don’t need to be genius to see that “stealing” private members of data structures from foreign libraries is dangerous and code much more probably won’t be compatible with future versions of these libraries. (Which is what we observe now?).

Thanks for returning Cxx.jl officially into [priorities](https://discourse.julialang.org/t/compiler-work-priorities/17623)! Could you guess when it will be ready?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [November 20, 2018, 5:25am UTC](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573/20 "2018-11-20T05:25:38Z")

</div>

> [@Liso](#):
>
> Unmaintanability was [hyperbole](https://en.wikipedia.org/wiki/Hyperbole) about sin and punishment. But one don’t need to be genius to see that “stealing” private members of data structures from foreign libraries is dangerous and code much more probably won’t be compatible with future versions of these libraries. (Which is what we observe now?).

LLVM/Clang have no guarantees on either their public or private APIs, so this distinction is more of an aesthetic choice for them. However, if you would like to volunteer or fund the work required to introduce public abstractions that contain the necessary functionality, you’re most welcome to do so.

[Next page](https://discourse.julialang.org/t/using-a-c-library-with-julia-1/17573.md?page=2)
