Last active
December 8, 2020 04:54
-
-
Save terasakisatoshi/b6a7121cd570f6739992345095b07d62 to your computer and use it in GitHub Desktop.
CxxWrap.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JL="$(dirname "$(dirname `which julia`)")" | |
PREFIX=`julia -e 'using CxxWrap; CxxWrap.prefix_path() |> print'` | |
g++ -fPIC -shared -std=c++17 \ | |
-I${PREFIX}/include/ \ | |
-L${PREFIX}/lib/ \ | |
-I${JL}/include/julia \ | |
-L${JL}/lib \ | |
hello.cpp -o libhello.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load the module and generate the functions | |
module CppHello | |
using CxxWrap | |
@wrapmodule(joinpath(".","libhello.so")) | |
function __init__() | |
@initcxx | |
end | |
end | |
# Call greet and show the result | |
@show CppHello.greet() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM julia:1.5.3 | |
RUN apt-get update && apt-get install -y \ | |
build-essential | |
RUN julia -e 'using Pkg; Pkg.add("CxxWrap"); Pkg.precompile()' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include "jlcxx/jlcxx.hpp" | |
std::string greet() | |
{ | |
return "hello, world"; | |
} | |
JLCXX_MODULE define_julia_module(jlcxx::Module& mod) | |
{ | |
mod.method("greet", &greet); | |
} |
Usage (using Docker)
$ docker build -t jl .
$ docker run --rm -it -v $PWD:/work -w /work jl bash -c 'bash build.sh && julia callcxx.jl'
CppHello.greet() = "hello, world"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Install CxxWrap.jl via Julia's REPL:
julia> using Pkg; Pkg.add("CxxWrap")
.Then, simply run:
bash build.sh && julia callcxx.jl
Related Topics
https://gist.github.com/terasakisatoshi/163ab1fc3ff1adab340d221eae33d218