LILAC
Language to language Interop LAyer Compiler
|
This sample describes how to create C# binding of C++ source...
See files used by this sample here.
We use CMakeLists.txt
to compile C++ sources(cxx/test.cxx
) to shared library:
CMAKE_EXPORT_COMPILE_COMMANDS=ON
make CMake to export compilation information to compile sources into compile_commands.json
required by libTooling
(clang
) to analyze C/C++ source.CMAKE_EXPORT_COMPILE_COMMANDS
must be ON
to use lilac. (CMake 3.5 or later is required)SHARED
.cxx::CXXModule
and cxx::CXXModule::Hello()
are export target (can be specified by [[lilac::export]]
)cxx::CXXModule::Hello()
prints Hello from C++!
to console.cmake -B build
configure CMake project with folder build
as build directory.compile_commands.json
will be generated at build directory.sym --from c++
make lilac
extract symbols from C++ sources-o lilac.xml
make lilac
place output to lilac.xml
-p build
make lilac
use build
as build directorycxx/test.cxx
), given arguments will be considered as analyzing target<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
to allow unsafe (such as pointers) codes<None Include="../build/libtest.so" CopyToOutputDirectory="PreserveNewest" />
to include build result of C++ project.../build/libtest.so
can be replaced by your build environmentJust use cxx::CXXModule().Hello()
(C++) as cxx.CXXModule().Hello()
(C#)!
bind --to c#
specifies target language is C#--sym lilac.xml
makes lilac
to use lilac.xml
as interface symbol--name test
assumes name of native library is libtest.so
or test.so
or libtest.dll
or test.dll
etc...-o MyConsole
let lilac
place C# binding to MyConsole/Test.cs
Generated C# binding for given C++ source:
Finally, We can run MyConsole
!
Run result is as:
If a message not shown or broken message printed, You may found a bug of lilac system. Please contact to developer.