openvpn3
openvpn3 copied to clipboard
How can I use openvpn3 in vckpg store in my cmake based project
OpenVPN3 is in the vcpkg store and I install it with
vcpkg install openvpn3
but I cant use it in my project because cmake can't found the openvpn3 package
find_package(openvpn3 REQUIRED)
target_link_libraries(myproject
PRIVATE
openvpn3::openvpn3
)
Hi,
Here is an example which works for me.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project (ovpnclitest)
find_path(OVPN3_INCLUDE_DIRS "openvpn/ovpncli.hpp")
find_library(OVPN3_LIB "ovpncli.lib")
find_library(MBEDTLS_LIB mbedtls)
find_library(MBEDCRYPTO_LIB mbedcrypto)
find_library(MBEDX509_LIB mbedx509)
add_executable (ovpnclitest main.cpp)
target_include_directories(ovpnclitest PRIVATE ${OVPN3_INCLUDE_DIRS})
target_link_libraries(ovpnclitest PRIVATE Iphlpapi.lib Wininet.lib Setupapi.lib Cfgmgr32.lib Rpcrt4.lib Fwpuclnt.lib Wtsapi32.lib ${OVPN3_LIB} ${MBEDTLS_LIB} ${MBEDCRYPTO_LIB} ${MBEDX509_LIB})
target_compile_definitions(ovpnclitest PRIVATE -DTAP_WIN_COMPONENT_ID=tap0901)
vcpkg.json:
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "ovpnclitest",
"version": "0.1",
"dependencies": [
"openvpn3"
]
}
CMakePresets.json:
{
"version": 2,
"configurePresets": [
{
"name": "default",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_TOOLCHAIN_FILE": {
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
}
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
]
}
main.cpp:
#include <asio.hpp>
#include <openvpn/common/platform.hpp>
#define OPENVPN_LOG_GLOBAL
#include <openvpn/log/logbasesimple.hpp>
#include <openvpn\ovpncli.hpp>
#include <openvpn\client\cliconstants.hpp>
#include <openvpn\options\merge.hpp>
using namespace openvpn;
class Client : public ClientAPI::OpenVPNClient
{
virtual bool pause_on_connection_timeout() override
{
return false;
}
virtual void event(const ClientAPI::Event& ev) override
{
}
virtual void external_pki_cert_request(ClientAPI::ExternalPKICertRequest& certreq) override
{
}
virtual void external_pki_sign_request(ClientAPI::ExternalPKISignRequest& signreq) override
{
}
virtual void log(const ClientAPI::LogInfo& log) override
{
std::cout << log.text << std::flush;
}
};
int main(int argc, char** argv) {
ProfileMerge pm(argv[1], "ovpn", "", ProfileMerge::FOLLOW_FULL, ProfileParseLimits::MAX_LINE_SIZE, ProfileParseLimits::MAX_PROFILE_SIZE);
ClientAPI::Config config;
config.content = pm.profile_content();
config.wintun = true;
Client client;
client.eval_config(config);
client.connect();
return 0;
}
Note that we do not maintain openvpn3 port in vcpkg and tap-windows6 driver support is broken there - the port packs openvpn3 into a library, however string constant which is uses to identity tap driver (TAP_WIN_COMPONENT_ID
) is not defined for that library. Same goes for ovpn-dco-win - required defines are missing. Wintun, however, works.
With that, I suggest to use openvpn3 from github repo until vcpkg port is fixed.
Thank you it very useful, save my all day but what about OpenSSL, how can i use that instead mbedtls?
Not with this vcpkg port, as mbedtls usage is hardcoded there. But you can (and I would say should) use openssl if you just do git clone of openvpn3 repo with something like
find_package(OpenSSL REQUIRED)
SET(SSL_LIBRARY OpenSSL::SSL)
list(APPEND CORE_DEFINES -DUSE_OPENSSL)
I'll try to fix vcpkg port in coming days and post an update.
Hello. I'm trying to use also the vcpkg port in my project (C++ and Qt creator, Qt5 and Windows 10).
What I'm getting is lots of unresolved symbols _cdecl openvpn::ClientAPI::*
I thought this means that there is a problem in ovpncli.lib
I ran dumpbin /exports ovpncli.lib
and I got no exported symbols from it.
I don't think this is normal, how can I link against a correct ovpncli.lib?
I went to the vcpkg one since I didn't manage to make a build of this library on windows + cannot find any built release
Note that vcpkg port is not supported by us and likely doesn't work. What problem exactly you experience with Windows build? Note that we have GitHub Actions script which builds on Windows https://github.com/OpenVPN/openvpn3/runs/6292913627?check_suite_focus=true You probably could get some ideas from it.
Note that we do not maintain openvpn3 port in vcpkg and tap-windows6 driver support is broken there - the port packs openvpn3 into a library, however string constant which is uses to identity tap driver (
TAP_WIN_COMPONENT_ID
) is not defined for that library. Same goes for ovpn-dco-win - required defines are missing. Wintun, however, works.With that, I suggest to use openvpn3 from github repo until vcpkg port is fixed.
I managed to add TAP_WIN_COMPONENT_ID=tap0901
to my preprocessor definitions which fixes that issue