Open sylvaticus opened 3 months ago
Crosspost from the discourse thread: https://discourse.julialang.org/t/can-someone-provide-a-simple-example-of-using-cxxwrap/115908/6
In the end I found it:
cd(@__DIR__)
Pkg.activate(".")
using CxxWrap
write("hello.cpp",
"""
#include <string>
#include "jlcxx/jlcxx.hpp"
std::string greet()
{
return "hello, world";
}
JLCXX_MODULE define_julia_module(jlcxx::Module& mod)
{
mod.method("greet", &greet);
}
""")
cxx_include_path = joinpath(CxxWrap.prefix_path(),"include")
julia_include_path = joinpath(Sys.BINDIR,"..","include","julia")
# Compile
cmd = `g++ -shared -fPIC -o libhello.so -I $julia_include_path -I $cxx_include_path hello.cpp`
run(cmd)
# Generate the function for Julia
@wrapmodule(() -> joinpath(pwd(),"libhello"))
# Call greet and show the result
@show greet()
I think it could be useful to start the documentation/readme with something on this line because of its reproducibility (in Linux at least) and focus on the sole CxxWrap API, without mixing it with the issues on how to compile it with CMake, that could be discussed later on....
Hello, I am trying to replicate the example in the readme on a Linux Ubuntu system with gcc/cmake installed but I am getting the following error:
When I run the command from the terminal I get
make: invalid option -- 'D'
I have tried to remove the D and to use two hypens (
--
), but still no success...By the way, if the examples are given as made from within Julia (using write/run), they would be easier to replicate....