Mizux / cmake-swig

Modern CMake C++ SWIG Sample
Apache License 2.0
177 stars 30 forks source link

how to test binding example (noob question) #11

Closed kurtsansom closed 3 years ago

kurtsansom commented 3 years ago

It appears that I am able to compile and build the cpp portion and it appears the dotnet bindings are "compiling" with some warnings. however I am stuck trying to test the csharp bindings either directly (It appears to be create a library) or importing the library in another dotnet project.

I am unable to get the following to work (but I am also pretty new to dotnet)

dotnet add reference ./<somepath>/Mizux.CMakeSwig/Mizux.CMakeSwig.csproj

and

using System;
using Mizux.CMakeSwig.Foo;

namespace thing
{
    class Program
    {
        static void Main(string[] args)
        {
            Foo obj = new Foo();
        }
    }
}
cd ./<somepath/thing
dotnet run

EDIT: I modified to follow the example in the next comment and the above edits now work

Mizux commented 3 years ago

1) when building, you'll generate the runtime nupkg (basically containing the c++ os specific code) and the generic .Net wrapper library package. By default they are stored/located in build-dir/dotnet.package IIRC so in your .csproj you need to add this "resource" path so dotnet cli will be able to find this reference package. ref: https://github.com/Mizux/cmake-swig/blob/a4450e3d95b3f54ee7732c38a3720c1865a27668/cmake/dotnet.cmake#L90-L98 https://github.com/Mizux/cmake-swig/blob/a4450e3d95b3f54ee7732c38a3720c1865a27668/cmake/dotnet.cmake#L117-L124

note: ".nupkg" is the .Net package format for a library/app. note2: you can also locally install them (should be in ~/.nugget/packages) so your project will find them (even if they are not published on nuget.org) ref: https://github.com/Mizux/cmake-swig/blob/a4450e3d95b3f54ee7732c38a3720c1865a27668/cmake/dotnet.cmake#L106

2) Take a look at the sample in ci for "usage" https://github.com/Mizux/cmake-swig/tree/main/ci/samples/dotnet

-> this is something I have to fix, in dotnet-native I did it, but notice the csproj.in which need to be generated so the "working" sample will be in build/dotnet/...

kurtsansom commented 3 years ago

Thank you. I think that was my main issue.