OpenVPN / openvpn3

OpenVPN 3 is a C++ class library that implements the functionality of an OpenVPN client, and is protocol-compatible with the OpenVPN 2.x branch.
https://openvpn.net
Other
998 stars 400 forks source link

Failed buildilng java client: java.lang.UnsatisfiedLinkError: no ovpncli in java.library.path #36

Open ninosvo opened 6 years ago

ninosvo commented 6 years ago

I've built the java client using 'build-linux' with one error

` ./build-linux SWIG JAVA CORE /Users/nino/src/ovpn3/core/client/ovpncli.cpp:28:10: fatal error: 'atomic' file not found

include

     ^

`

When I try to run the java class there is a link error?

$ java -Djava.library.path=. Main XYZ.ovpn Exception in thread "main" java.lang.UnsatisfiedLinkError: no ovpncli in java.library.path

The following relevant files are present in the javacli directory after the build

ovpncli.class ovpncli.i ovpncli.java ovpncliJNI.class ovpncliJNI.java ovpncli_wrap.cxx ovpncli_wrap.h

Where is the actual native library as it doesn't seem to find it?

ninosvo commented 6 years ago

Update: Not sure if this helps as I'm not familiar with c/c++ but I've looked around and tried modifying the build-linux script to use clang++ instead of g++ as follows: PATH="/usr/local/opt/llvm/bin:$PATH" clang++ -std=c++11 -stdlib=libc++

This has changed the error

` ./build-linux SWIG JAVA CORE In file included from /Users/nino/src/ovpn3/core/client/ovpncli.cpp:90: In file included from /Users/nino/src/ovpn3/core/openvpn/init/initprocess.hpp:34: In file included from /Users/nino/src/ovpn3/core/openvpn/compress/compress.hpp:152: /Users/nino/src/ovpn3/core/openvpn/compress/lz4.hpp:30:10: fatal error: 'lz4.h' file not found

include

     ^~~~~~~

1 error generated. `

Any help is much appreciated.

ninosvo commented 6 years ago

Update: (Sorry for the spam) Ok so I've modified the build-linux script further to try make it work for OSX which is the platform I'm trying to build this on. Can't seem to get passed these errors:

/Users/nino/src/ovpn3/core/openvpn/client/cliconnect.hpp:221:35: error: initialized lambda captures are a C++14 extension [-Werror,-Wc++14-extensions] restart_wait_timer.async_wait([self=Ptr(this), gen=generation](const openvpn_io::error_code& error) ^ fatal error: too many errors emitted, stopping now [-ferror-limit=]

Has anyone got the build working on OSX for the java client?

schwabe commented 6 years ago

you will need -std=c++14 or -std=c++1y to compile the client. As a side note, I am building the OpenVPN3 C++ library for my own Android client with my cmake build script. (https://github.com/schwabe/ics-openvpn/blob/master/main/src/main/cpp/CMakeLists.txt). Maybe looking at it will help to figure out compiling.

ninosvo commented 6 years ago

I have tried setting both these flags and confirm via echo it's using clang V5.0.1 (which should support c++14) and doesn't seems to make any difference still the same compile error. Strange. I'm trying to build for use in a plain java app.

ninosvo commented 6 years ago

Update: Your suggestion for -std=c++14 works but the option needs to be put AFTER all the other options (There must have been something else in the includes overriding it)

With the following changes I was able to get it to compile successfully:

PLATFORM=osx TARGET=osx PATH="/usr/local/opt/llvm/bin:$PATH" # Clang V5.0.1

Note: -DLZ4_DISABLE_DEPRECATE_WARNINGS and -std=c++14 required near the end:

clang++ \ $CXX_COMPILER_FLAGS \ $PLATFORM_FLAGS \ $LIB_OPT_LEVEL $LIB_FPIC \ -Wall -Werror -Wno-sign-compare -Wno-unused-parameter \ -Wno-unused-local-typedefs -Wno-unused-private-field \ $vis1 \ $ssl_def \ -DUSE_ASIO \ -DASIO_STANDALONE \ -DASIO_NO_DEPRECATED \ -DLZ4_DISABLE_DEPRECATE_WARNINGS \ -DHAVE_LZ4 \ -I$O3/core/client \ -I$O3/core \ -I$DEP_DIR/asio/asio/include \ $ssl_inc \ -I$DEP_DIR/lz4/lz4-$PLATFORM/include \ -std=c++14 \ -c $O3/core/client/ovpncli.cpp

There was then some errors with the linking phase which I fixed by chaning -soname option to -install_name and adding jni.h headers.

-I$JAVA_HOME/include -I$JAVA_HOME/include/darwin \ -shared -Wl,-install_name,libovpncli.so \

However it still cannot find the libovpncli.so?

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: can't open file: libovpncli.so (No such file or directory)

I feel like I'm almost there and will then be able to contribute an OSX build script, any help is much appreciated?