Skip to content

benlorenz/libcxxwrap-julia

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
Aug 7, 2020
Dec 28, 2022
Dec 29, 2022
Aug 7, 2020
Apr 19, 2023
Oct 30, 2023
Sep 2, 2023
Mar 23, 2023
Aug 22, 2023
Mar 23, 2023
Aug 22, 2023
May 30, 2022
Sep 22, 2019
May 22, 2018
Aug 24, 2023

Repository files navigation

JlCxx

test-linux-mac test-win

This is the C++ library component of the CxxWrap.jl package, distributed as a regular CMake library for use in other C++ projects. To build a Julia interface to a C++ library, you need to build against this library and supply the resulting library as a binary dependency to your Julia package. The testlib-builder directory contains a complete example of how to build and distribute these binaries, or you can use the BinaryBuilder.jl wizard to generate the builder repository.

See the CxxWrap.jl README for more info on the API.

Building libcxxwrap-julia

Obtaining the source

Simply clone this repository, e.g.:

git clone https://github.com/JuliaInterop/libcxxwrap-julia.git

You can also manage everything directly from Visual Studio Code using "clone git repository" on the start screen.

Preparing the install location

Julia loads the libcxxwrap-julia through the libcxxwrap_julia_jll package, which is built automatically by BinaryBuilder. To tell Julia to use self-compiled binaries, one way is to use an override directory. To do this, check out libcxxwrap_julia_jll for development:

pkg> develop libcxxwrap_julia_jll

Next, import the package and call the dev_jll function:

julia> import libcxxwrap_julia_jll
julia> libcxxwrap_julia_jll.dev_jll()

Configuring and building

The last command should output the path to the devved JLL, e.g. /home/user/.julia/dev/libcxxwrap_julia_jll. In that directory, there will be a subdirectory called override which will contain the binaries from the Julia artifacts distribution. This directory should be completely emptied and then used as build directory from cmake, e.g. in a terminal do:

cd /home/user/.julia/dev/libcxxwrap_julia_jll/override
rm -rf *
cmake -DJulia_PREFIX=/home/user/path/to/julia /path/to/source/of/libcxxwrap-julia
cmake --build . --config Release

Here, /path/to/source/of/libcxxwrap-julia is the cloned git repository.

Building libcxxwrap-julia requires a C++ compiler which supports C++17 (e.g. GCC 7, clang 5; for macOS users that means Xcode 9.3).

The main CMake option of interest is Julia_PREFIX, which should point to the Julia installation you want to use. The PREFIX is a directory, one containing the bin and lib directories and so on. If you are using a binary download of Julia (https://julialang.org/downloads/), this is the top-level directory; if you build Julia from source (https://github.com/JuliaLang/julia), it would be the usr directory of the repository. Below we will call this directory /home/user/path/to/julia, but you should substitute your actual path in the commands below.

Instead of specifying the prefix, it is also possible to directly set the Julia executable, using:

cmake -DJulia_EXECUTABLE=/home/user/path/to/julia/bin/julia ../libcxxwrap-julia

Next, you can build your own code against this by setting the JlCxx_DIR CMake variable to the build directory (libcxxwrap-julia-build) used above, or add it to the CMAKE_PREFIX_PATH CMake variable.

Using the compiled libcxxwrap-julia in CxxWrap

Following the above instructions, Julia will now automatically use the compiled binaries. You can verify this using:

julia> using CxxWrap
julia> CxxWrap.prefix_path()
"/home/user/.julia/dev/libcxxwrap_julia_jll/override"

An alternative method of using self-compiled binaries is the Overrides.toml file, to be placed in .julia/artifacts:

[3eaa8342-bff7-56a5-9981-c04077f7cee7]
libcxxwrap_julia = "/path/to/libcxxwrap-julia-build"

More details here.

The file can be generated automatically using the OVERRIDES_PATH, OVERRIDE_ROOT and APPEND_OVERRIDES_TOML Cmake options, with the caveat that each CMake run will append again to the file and make it invalid, i.e. this is mostly intended for use on CI (see the appveyor and travis files for examples).

Building on Windows

On Windows, building is easiest with Visual Studio 2019, for which the Community Edition with C++ support is a free download. You can clone the https://github.com/JuliaInterop/libcxxwrap-julia.git repository using the built-in git support, and configure the Julia_PREFIX option from the built-in CMake support. See the Visual Studio docs for more info.

Binaries for the main branch

Binaries for the main branch are published at https://github.com/barche/libcxxwrap_julia_jll.jl, you can install them (in Pkg mode, hit ]) using:

add https://github.com/barche/libcxxwrap_julia_jll.jl.git

About

C++ library for backing CxxWrap.jl

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 87.2%
  • CMake 10.6%
  • Julia 2.2%