tjeu
March 28, 2019, 7:57pm
1
Is it possible to build libvyosconfig for Windows (with Cygwin)?
I’m working on an C# application that needs to generate VyOS configuration files. My goal is to create a .NET Standard library with bindings for VyOS ConfigTree.
I’ve got configtree.py
working on an Ubuntu system. It only depends on libvyosconfig.so.0
. But in order to use configtree.py
on a Windows system, libvyosconfig has to be build for Windows.
The Makefile
of libvyosconfig seems to be multiplatform, but I have no experience with OCaml.
ifeq ($(OSTYPE),$(filter $(OSTYPE),Win32 Cygwin))
$(BUILDDIR)/libvyosconfig$(EXTDLL): $(CAML_INIT) $(LIBFILES)
ocamlfind opt -o $@ -linkpkg -output-obj -verbose -package $(PACKAGES) $^
else ifeq ($(SYSTEM),$(filter $(SYSTEM),macosx))
$(BUILDDIR)/libvyosconfig$(EXTDLL): $(CAML_INIT) $(LIBFILES)
ocamlfind opt -o $@ -linkpkg -runtime-variant _pic -verbose -ccopt -dynamiclib -package $(PACKAGES) $^
else
$(BUILDDIR)/libvyosconfig$(EXTDLL): $(CAML_INIT) $(LIBFILES)
ocamlfind opt -o $@ -linkpkg -output-obj -runtime-variant _pic -verbose -package $(PACKAGES) -ccopt "-Wl,-soname,libvyosconfig.so.0" $^
endif
Does anyone have suggestions for compiling libvyosconfig for Windows?
Should I try GitHub - ocaml-cross/opam-cross-windows: An OCaml cross-toolchain for Windows and several useful libraries , OCaml for Windows or some other tool?
tjeu
March 29, 2019, 7:06am
2
This sample .NET Core application calls libvyosconfig.so.0
functions.
namespace ConfigTree
{
class Program
{
static void Main(string[] args)
{
var config = Config.from_string("system { host-name vyos \n } interfaces { dummy dum0 { address 192.0.2.1/24 \n address 192.0.2.20/24 \n disable \n } }");
Console.WriteLine("config* = " + config);
var toStringResult = Config.to_string(config);
Console.WriteLine("config.to_string(): " + toStringResult);
}
}
public static class Config
{
[DllImport("libvyosconfig.so.0", CharSet = CharSet.Ansi)]
public static extern IntPtr from_string(string s);
[DllImport("libvyosconfig.so.0", CharSet = CharSet.Ansi)]
public static extern string to_string(IntPtr self);
}
}
It produces this output on Ubuntu (WSL):
config* = 26827648
config.to_string(): system {
host-name "vyos"
}
interfaces {
dummy dum0 {
address "192.0.2.1/24"
address "192.0.2.20/24"
disable { }
}
}
I want to do the same on the Windows platform, but don’t know how to build libvyosconfig.