Need C# interface for Xamarin Android development based on OpenVPN library
I'm currently trying to use SWiG to create an interface for ovpncli.hpp in order to be able to access the API from my C# project.
First of all, I would like to know why Visual Studio (tested with 2015 and 2017) ignores all directories in the OpenVPN project folder as like as shown in the image https://imgur.com/a/cXoj6Nj. I basically added the OpenVPN project to my current project using Visual Studio.
And my main problem is that SWiG ignores all specified headers if I compile the file ovpncli.i with the following command:
C:\swigwin-3.0.12\swig -c++ -csharp -outdir C:\swigwin-3.0.12\Generated ovpncli.i
Please check this image https://imgur.com/a/3hOoy7u
Sorry for posting this in the issues section but this request is really urgent for me. I apologize for the inconvenience.
Thank you.
Sincerely, Chris
Well, changing the path like this https://imgur.com/a/j3IfDXJ works but it can't solve the other header files now. I guess that's because VisualStudio ignores all directories from OpenVPN project?
@jamesyonan @lstipakov could someone help me, please?
Yep, Visual Studio just ignores file system structure. https://stackoverflow.com/a/645095/227024
@lstipakov Sorry, but this doesn't help. References in the OpenVPN project cannot be resolved as all class files are located in the "index" directory. Here is a random class I picked to show: https://imgur.com/a/hdoLFF3
Did you experience problem with SWIG / C# or with compiling test client?
I cannot help with first one. For the test client, did you follow steps in README? You need to define environment variable OVPN3_ROOT which should point to a parent directory of ovpn3 project.
https://imgur.com/a/8MlQUmN
@lstipakov I experience issues using SWiG / C# https://imgur.com/a/73P7tWW using the following command to compile
C:\swigwin-3.0.12\swig -c++ -csharp -outdir C:\swigwin-3.0.12\Generated ovpncli.i
@lstipakov Do you have any idea how to solve the issue?
@lstipakov Finally, I was able to solve the issue by using the "-I" parameter of SWiG tool.
However, I am trying test the API if it works as expected but I am not really sure how to use the classes. https://i.imgur.com/JKUOOtd.png
Sorry, I am not that familiar with SWIG, but glad you've made it work.
As for another problem - you need to instantiate ClientAPI::Config, see https://github.com/OpenVPN/openvpn3/blob/master/test/ovpncli/cli.cpp#L827
Hello @lstipakov, if I try to access the ClientAPI_Config() it returns the following exception:
"DllNotFoundException: The DLL "ovpncli": The specified module was not found. (Exception of HRESULT: 0x8007007E) cannot be loaded."
I'm far from a Windows developer, and even less a C#/.net developer. But from the error above, it smells like client/ovpncli.cpp was never compiled into a library.
Have a look what is done inside javacli/build-linux or javacli/build-android. This is part of the build process to generate a SWIG module for Java, where the depending shared library is built as well.
@dsommers , does build-linux and build-android file have to be executed on Linux machine, or can I do this on Windows too?
@XXvevo look at https://github.com/schwabe/ics-openvpn/tree/master/main/src/main/cpp for Android. That build works on Windows/Mac/Linux.
@schwabe is there any possibility to contact you by email for acquiring a commercial license for ics-openvpn?
@XXvevo AFAICT build-linux is at least expecting a Linux-like environment, and the same is most likely true for build-android too.
@lstipakov @dsommers @schwabe @tadovas @jamesyonan @ordex @mattock
After a long and extremely intensive research I tried to create a C# interface based on a modified form of build-linux script.
On my computer I set up a virtual Ubuntu 16.04.5 server and installed all dependencies including the Mono compiler.
When I run the build-csharp script (https://pastebin.com/utTj8Xzv), I get the following output:
root@UBUNTU-OPENVPN:~/ovpn3/core/javacli# ./build-chsarp
SWIG
/root/ovpn3/core/client/ovpncli.hpp:537: Warning 314: 'event' is a C# keyword, renaming to '_event'
/root/ovpn3/core/client/ovpncli.hpp:581: Warning 473: Returning a pointer or reference in a director method is not recommended.
CSHARP
Microsoft (R) Visual C# Compiler version 2.6.0.62309 (d3f6b8e7)
Copyright (C) Microsoft Corporation. All rights reserved.
error CS5001: Program does not contain a static 'Main' method suitable for an entry point
I changed the script only slightly based on the build-linux script because I don't want to break anything. There are some things, like JDK, which is not needed anymore in this case, but I don't know how to extend it.
Does anyone have an idea? We are also willing to pay money to the OpenVPN project and the person who can help us.
Thank you.
I tried compiling using mcs /target:library /out:openvpn.dll *.cs instead but Visual Studio cannot find the ovpncli reference as shown here https://imgur.com/a/mGwElGP. I have to find a way to include the ovpncli in the DLL or otherwise. My current build-csharp script can be found here https://pastebin.com/F56MV5Fk.
If I try to compile build-linux it says
OpenVPNClientThread.java:203: error: method does not override or implement a method from a supertype
@Override
^
1 error
and if I remove the @Override annotation from file, it says
In file included from /root/ovpn3/core/client/ovpncli.cpp:30:0:
/root/ovpn3/core/openvpn/io/io.hpp:28:20: fatal error: asio.hpp: No such file or directory
compilation terminated.
Java version:
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-3)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
Please fix this issue.
New issue has been created and can be reviewed here.
@XXvevo you failed to build the dependency or install the dependencies (ASIO). There is a linux/build-all script.
@schwabe
export O3=~/ovpn3
root@UBUNTU-OPENVPN:~/ovpn3/core/scripts/linux# ./build-all
./build-all: line 7: cd: /root/linux: No such file or directory
@XXvevo yes the scripts are not as robust as they could be. But please try to solve the problem yourself. The library is not exactly easy to use and I would someone who tries to use the library to at least be able to open a shell script and figure out that DEP_DIR variable needs also be set.
@schwabe Please consider to add this to the documentary otherwise people will continue asking for help.
is there any solution?
No, and since we are not using C# ourselves, we will accept pull request to improve/make a C# binding but currently this is not something we actively work on.
It was possible to build the openvpn for both android and iOS and use it from xamarin forms. Minimum coding is required but some scripting and manual copying is necessary. I am not experienced enough to create a standard library yet. In the upcoming months, I will try to create a general app for showcase. Till then, if anybody want to try it, can follow here : https://github.com/sakib1361/Xamarin-VPN
N.B the very recent build requires some more modification as the generated c# code naming conflicts with current naming. (Mainly using get/set) Hopefully somebody experience enough can build what I tried to do and make a library out of it, Thanks,
N.B 2 : Also if Im breaking any law/license, please let me know.
@sakib1361 the license of Openvpn3 is AGPL3 which means that you cannot use this code to publish an app on iOS.
Thanks. I'm not actively developing an app to publish. If u want, I can take down the git. Just wanted to help as it was possible for me to port a complex library to xamarin. Both on android and iOS. Currently I am trying to see if I can directly compile the c++ library to xamarin without the platform specific ports.
No need to take down the source code. But you should clearly mark your work AGPLv3 and add the correct license file to your project. And it probably would be good if you also in a readme file made it clear that GPL licenced software is not acceptable in the Apple Appstore.
The project itself can be any license but building it with openvpn3 will make AGPLv3.