# Can someone provide a simple example of using CxxWrap?

**URL:** <https://discourse.julialang.org/t/can-someone-provide-a-simple-example-of-using-cxxwrap/115908>\
**Category:** General Usage\
**Tags:** cxx, cxxwrap\
**Created:** [June 20, 2024, 8:39am UTC](https://discourse.julialang.org/t/can-someone-provide-a-simple-example-of-using-cxxwrap/115908 "2024-06-20T08:39:41Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 21, 2024, 9:19am UTC](https://discourse.julialang.org/t/can-someone-provide-a-simple-example-of-using-cxxwrap/115908/6 "2024-06-21T09:19:52Z")

</div>

I think I got it.

This compiles the “lib”, loads it and calls it in the simplest way:

```julia
using Pkg
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()

```

---

_[View the full topic](https://discourse.julialang.org/t/can-someone-provide-a-simple-example-of-using-cxxwrap/115908)._
