OpenVPN / OpenVPN/openvpn3

Has anyone compiled this project on a Windows system before?

Open
#387 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.2k
Forks
467
PR merge metrics
No merged PRs in 30d

Description

I want to get an ovpncli that calls JNI in Java. The Mac system can compile and build ovpnclilib. Windows, which can be compiled successfully but fails to build.
envs:

  • Visual Studio 2022 (Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe)
  • lzo-2.10
  • swigwin-4.3.1
  • asio:x64-windows@1.32.0 -- C:/Users/peng/Desktop/src/openvpn3/deps/vcpkg-ports\asio
  • fmt:x64-windows@11.0.2#1
  • gtest:x64-windows@1.17.0#1
  • jsoncpp:x64-windows@1.9.6
  • lz4:x64-windows@1.10.0
  • openssl:x64-windows@3.5.1
  • pkgconf:x64-windows@2.5.1
  • tap-windows6:x64-windows@9.21.2-0e30f5c#2
  • vcpkg-cmake:x64-windows@2024-04-23
  • vcpkg-cmake-config:x64-windows@2024-05-23
  • vcpkg-cmake-get-vars:x64-windows@2025-05-29
  • vcpkg-tool-meson:x64-windows@1.8.2
  • xxhash:x64-windows@0.8.3

include(findcoredeps)
include(findswigdeps)

if (BUILD_SWIG_LIB)
    set_property(SOURCE ovpncli.i PROPERTY CPLUSPLUS ON)
    if (NOT MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        # Swig generates code with deprecated python declarations
        set_property(SOURCE ovpncli.i PROPERTY GENERATED_COMPILE_OPTIONS -Wno-deprecated-declarations -Wno-sometimes-uninitialized -Wno-class-memaccess -Wno-unused-function -Wno-unknown-warning-option)
    endif()

    project(ovpncli)

# 设置Java 8 JNI头文件路径

    set(JAVA_INCLUDE_PATH "C:/Program Files/Java/jdk1.8.0_202/include")
    set(JAVA_INCLUDE_PATH2 "C:/Program Files/Java/jdk1.8.0_202/include/win32")  # 如linux/darwin
    set(JAVA_AWT_INCLUDE_PATH "C:/Program Files/Java/jdk1.8.0_202/include")
    set(JAVA_AWT_LIBRARY "C:/Program Files/Java/jdk1.8.0_202/jre/lib")
    set(JAVA_JVM_LIBRARY "C:/Program Files/Java/jdk1.8.0_202/jre/bin/server")  # 或lib/jvm

    find_package(JNI REQUIRED)
    include_directories(${JNI_INCLUDE_DIRS})
    include_directories(C:/Users/peng/Desktop/src/openvpn3/client)

    set(CMAKE_SWIG_FLAGS "-package" "com.onepro.hyperone.daemon.desktop.ovpn")

    swig_add_library(ovpnclilib
        TYPE SHARED
        LANGUAGE java
        SOURCES ovpncli.cpp  ovpncli.i
        )
    set_property(TARGET ovpnclilib PROPERTY SWIG_INCLUDE_DIRECTORIES ${CORE_DIR})

    add_core_dependencies(ovpnclilib)

    # Use proper python library name to generate _ovpncli.so/dylib/dll
    set_target_properties(ovpnclilib PROPERTIES OUTPUT_NAME "_ovpncli")
    set_target_properties(ovpnclilib PROPERTIES PREFIX "")

endif ()

compile and build result

PS C:\Users\peng\Desktop\src\openvpn3> cmake --preset win-x64-release
-- Running vcpkg install
正在检测三元组 x64-windows 的编译器哈希...
已找到编译器: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe
已安装以下包:
    asio:x64-windows@1.32.0 -- C:/Users/peng/Desktop/src/openvpn3/deps/vcpkg-ports\asio
    fmt:x64-windows@11.0.2#1
    gtest:x64-windows@1.17.0#1
    jsoncpp:x64-windows@1.9.6
    lz4:x64-windows@1.10.0
    openssl:x64-windows@3.5.1
    pkgconf:x64-windows@2.5.1
    tap-windows6:x64-windows@9.21.2-0e30f5c#2
  * vcpkg-cmake:x64-windows@2024-04-23
  * vcpkg-cmake-config:x64-windows@2024-05-23
  * vcpkg-cmake-get-vars:x64-windows@2025-05-29
  * vcpkg-tool-meson:x64-windows@1.8.2
    xxhash:x64-windows@0.8.3
asio 提供 CMake 目标:

  # 这是启发式生成的,并且可能不正确
  find_package(asio CONFIG REQUIRED)
  target_link_libraries(main PRIVATE asio::asio)

asio 提供 pkg-config 模块:

  # A cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.
  asio

The package fmt provides CMake targets:

    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt)

    # Or use the header-only version
    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt-header-only)

The package gtest is compatible with built-in CMake targets:

    enable_testing()

    find_package(GTest CONFIG REQUIRED)
    target_link_libraries(main PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)

    add_test(AllTestsInMain main)

jsoncpp 提供 CMake 目标:

  # 这是启发式生成的,并且可能不正确
  find_package(jsoncpp CONFIG REQUIRED)
  target_link_libraries(main PRIVATE JsonCpp::JsonCpp)

jsoncpp 提供 pkg-config 模块:

  # 这是启发式生成的,并且可能不正确
  find_package(jsoncpp CONFIG REQUIRED)
  target_link_libraries(main PRIVATE JsonCpp::JsonCpp)

jsoncpp 提供 pkg-config 模块:

  # A C++ library for interacting with JSON
  jsoncpp

lz4 provides CMake targets:

  find_package(lz4 CONFIG REQUIRED)
  target_link_libraries(main PRIVATE lz4::lz4)

lz4 provides pkg-config modules:

  liblz4

openssl is compatible with built-in CMake targets:

  find_package(OpenSSL REQUIRED)
  target_link_libraries(main PRIVATE OpenSSL::SSL)
  target_link_libraries(main PRIVATE OpenSSL::Crypto)

pkgconf 提供 pkg-config 模块:

  # a library for accessing and manipulating development framework configuration
  libpkgconf

tap-windows6 是仅限标头的,可通过以下方式从 CMake 使用:

  find_path(TAP_WINDOWS6_INCLUDE_DIRS "tap-windows.h")
  target_include_directories(main PRIVATE ${TAP_WINDOWS6_INCLUDE_DIRS})

xxhash 提供 CMake 目标:

  # 这是启发式生成的,并且可能不正确
  find_package(xxHash CONFIG REQUIRED)
  target_link_libraries(main PRIVATE xxHash::xxhash)

xxhash 提供 pkg-config 模块:

  # extremely fast hash algorithm
  libxxhash

已在 512 us 内成功完成所有请求的安装
-- Running vcpkg install - done
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.22631.
lzo found, running lzo compression tests
-- Configuring done (3.4s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Users/peng/Desktop/src/openvpn3/build/msvc/amd64

PS C:\Users\peng\Desktop\src\openvpn3> cmake --build --preset win-x64-release --target ovpnclilib
适用于 .NET Framework MSBuild 版本 17.14.14+a129329f1

1>Swig compile ovpncli.i for java
C:\Users\peng\Desktop\src\openvpn3\cmake..\openvpn\client\dns_options.hpp(81): warning 503: Can't wrap 'operator ==' unless renamed to a valid i
dentifier. [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
C:\Users\peng\Desktop\src\openvpn3\cmake..\openvpn\client\dns_options.hpp(125): warning 503: Can't wrap 'operator ==' unless renamed to a valid
identifier. [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
C:\Users\peng\Desktop\src\openvpn3\cmake..\openvpn\client\dns_options.hpp(289): warning 503: Can't wrap 'operator ==' unless renamed to a valid
identifier. [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
C:\Users\peng\Desktop\src\openvpn3\cmake..\openvpn\client\dns_options.hpp(358): warning 503: Can't wrap 'operator ==' unless renamed to a valid
identifier. [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
正在扫描源以查找模块依赖项...
ovpncli.cpp
ovpncliJAVA_wrap.cxx
正在编译...
ovpncli.cpp
ovpncliJAVA_wrap.cxx
正在创建库 C:/Users/peng/Desktop/src/openvpn3/build/msvc/amd64/client/Release/_ovpncli.lib 和对象 C:/Users/peng/Desktop/src/openvpn3/build/msvc/amd64
/client/Release/_ovpncli.exp
ovpncliJAVA_wrap.obj : error LNK2001: 无法解析的外部符号 "private: virtual void __cdecl openvpn::ClientAPI::OpenVPNClient::connect_attach(void)" (?connect
_attach@OpenVPNClient@ClientAPI@openvpn@@EEAAXXZ) [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
ovpncliJAVA_wrap.obj : error LNK2001: 无法解析的外部符号 "private: virtual void __cdecl openvpn::ClientAPI::OpenVPNClient::connect_pre_run(void)" (?connec
t_pre_run@OpenVPNClient@ClientAPI@openvpn@@EEAAXXZ) [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
ovpncliJAVA_wrap.obj : error LNK2001: 无法解析的外部符号 "private: virtual void __cdecl openvpn::ClientAPI::OpenVPNClient::connect_run(void)" (?connect_ru
n@OpenVPNClient@ClientAPI@openvpn@@EEAAXXZ) [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
ovpncliJAVA_wrap.obj : error LNK2001: 无法解析的外部符号 "private: virtual void __cdecl openvpn::ClientAPI::OpenVPNClient::connect_session_stop(void)" (?c
onnect_session_stop@OpenVPNClient@ClientAPI@openvpn@@EEAAXXZ) [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]
ovpncliJAVA_wrap.obj : error LNK2001: 无法解析的外部符号 "private: virtual class openvpn::Stop * __cdecl openvpn::ClientAPI::OpenVPNClient::get_async_stop
(void)" (?get_async_stop@OpenVPNClient@ClientAPI@openvpn@@EEAAPEAVStop@3@XZ) [C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\ovpnclil
ib.vcxproj]
C:\Users\peng\Desktop\src\openvpn3\build\msvc\amd64\client\Release_ovpncli.dll : fatal error LNK1120: 5 个无法解析的外部命令 [C:\Users\peng\Desktop\src\op
envpn3\build\msvc\amd64\client\ovpnclilib.vcxproj]


Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Windows build with the win-x64-release CMake preset and target ovpnclilib. Inspect the shown CMakeLists.txt, ovpncli.cpp, ovpncli.i, and the linker output for the missing OpenVPNClient symbols; done means the Java JNI library links successfully on Windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.