master
Quick test on how to dip into C/C++ from C# using your own shared C++ libraries
Building
Building and testing is quite quick and only involves several steps. Before proceeding, it should be noted that this quick test targets Linux. This makes a difference because in Linux C++ shared libraries have a *.so file extension compared to Windows having a *.dll file extension. The Program.cs file is looking for a shared library with an extension ending is *.so. As is this test will not work on Windows without some modifications.
Required
- Linux
- .NET Core 3.1
- GCC >= 7 or clang >= 7
Building C++ library
- Change into the C++ Libs directory and create a build directory
cd Libs; mkdir build
- Build the C++ library
cd build; cmake -DCMAKE_BUILD_TYPE=DEBUG ..; make
- Copy the library to the root of the project
cp libTestExample.so ../../
Building .NET console software
- Ensure that you are in the root of the project. Then build the software
dotnet build
- Copy the C++ library to where the executable is build
cp libTestExample.so bin/Debug/netcoreapp3.1/
- Run the software
dotnet run
- The .NET code is calling a function from the C++ library that was built. The result is the sum of two integers
Description
Languages
C#
38.6%
C++
37.4%
CMake
24%