# Interface to c++ code

**URL:** <https://discourse.julialang.org/t/interface-to-c-code/1865>\
**Category:** General Usage\
**Tags:** cxx, interoperability\
**Created:** [February 3, 2017, 12:57pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865 "2017-02-03T12:57:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndbecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndbecker/32/10829_2.png) [@ndbecker](https://discourse.julialang.org/u/ndbecker)\
**Post date:** [February 3, 2017, 12:57pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/1 "2017-02-03T12:57:26Z")

</div>

I know that perhaps in the future I could use cxx, but for now that doesn’t seem an option because it requires a non-standard build of julia. So I’m playing with ccall interface.

I want to use code that represents multi-dimension c++ arrays using ndarray library [https://github.com/ndarray/ndarray](https://github.com/ndarray/ndarray).  
It should be simple to convert Array from julia to c++ nd::array with a c-code wrapper, and conversion could be automatic using cconvert mechanism. I’m thinking I could represent this ndarray type in julia with a type holding a void\* pointer.

I don’t know how to go in the other direction: returning a c++ nd::array to julia. Even if I could arrange to convert a raw pointer to the data into a julia array, that doesn’t address the memory management.

Any ideas?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 3, 2017, 1:26pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/2 "2017-02-03T13:26:46Z")

</div>

I believe that the cxx package just works on 0.5.

---

<div class="post-metadata">

**Author:** ![ndbecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndbecker/32/10829_2.png) [@ndbecker](https://discourse.julialang.org/u/ndbecker)\
**Post date:** [February 3, 2017, 1:48pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/3 "2017-02-03T13:48:42Z")

</div>

I’m happy to hear that cxx just works with 0.5. Unfortunately, I’m trying  
to use fedora packaged julia, which doesn’t include julia source. It looks  
like the source is needed.

Without it I get:

```julia
julia> Pkg.build("Cxx")
INFO: Building Cxx
writing path.jl file
Tuning for julia installation at /usr/bin with sources possibly at
/usr/bin/../..
INFO: Building julia binary build
Not building debug library because corresponding julia DEBUG library does
not exist.
Not building release library because corresponding julia RELEASE library
does not exist.
To build, simply run the build again once the library at
To build, simply run the build again once the library at
/libjulia-debug.so
/libjulia.so
has been built.
has been built.
 cc -E -P -I/usr/bin/../../src/support -I/usr/bin/../include
-Isrc/clang-3.7.1/lib -Ibuild/clang-3.7.1/include -Isrc/clang-3.7.1/include
-Isrc/llvm-3.7.1/include -Ibuild/llvm-3.7.1/include -DJULIA
../src/cenumvals.jl.h > build/clang_constants.jl
/bin/sh: build/clang_constants.jl: No such file or directory
BuildBootstrap.Makefile:175: recipe for target 'build/clang_constants.jl'
failed
make: *** [build/clang_constants.jl] Error 1
=================================================[ ERROR: Cxx
]=================================================

LoadError: failed process: Process(`make -j4 -f BuildBootstrap.Makefile
BASE_JULIA_BIN=/usr/bin BASE_JULIA_SRC=/usr/bin/../..`, ProcessExited(2))
[2]
while loading /home/nbecker/.julia/v0.5/Cxx/deps/build.jl, in expression
starting on line 41

```

Looking at BuildBootstrap.Makefile, it looks to me that BASE\_JULIA\_SRC  
needs to point to julia sources  
Running manually I get:

```julia
make -j4 -f BuildBootstrap.Makefile BASE_JULIA_BIN=/usr/bin
BASE_JULIA_SRC=/usr/bin/../..
BuildBootstrap.Makefile:6: /usr/bin/../../deps/Versions.make: No such file
or directory
BuildBootstrap.Makefile:7: /usr/bin/../../Make.user: No such file or
directory
make: *** No rule to make target '/usr/bin/../../Make.user'. Stop.

```

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [February 3, 2017, 2:06pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/4 "2017-02-03T14:06:55Z")

</div>

I don’t think the julia developers are involved in maintaining the linux binaries. There are recommended installation instructions for fedora on [http://julialang.org/downloads/platform.html](http://julialang.org/downloads/platform.html)

---

<div class="post-metadata">

**Author:** ![ndbecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndbecker/32/10829_2.png) [@ndbecker](https://discourse.julialang.org/u/ndbecker)\
**Post date:** [February 3, 2017, 2:27pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/5 "2017-02-03T14:27:17Z")

</div>

I don’t think that will help. The instructions say to use

```julia
sudo dnf copr enable nalimilan/julia
sudo yum install julia

```

It looks like the packages from copr (nalimilan/julia) are exactly the same as the standard julia packages from fedora, which I already have installed - they don’t contain the needed files e.g, deps/Versions.make that the Makefile for Cxx expects.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [February 3, 2017, 3:42pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/6 "2017-02-03T15:42:54Z")

</div>

We’re looking into it.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [February 3, 2017, 6:05pm UTC](https://discourse.julialang.org/t/interface-to-c-code/1865/7 "2017-02-03T18:05:04Z")

</div>

See [this Cxx issue](https://github.com/Keno/Cxx.jl/issues/321#issuecomment-277317855) for an analysis of the problem and a temporary hack.
