Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Use OpenVPN3 Libraryi With CMAKE ? #316

Open
deletexl opened this issue Jul 8, 2024 · 1 comment
Open

How to Use OpenVPN3 Libraryi With CMAKE ? #316

deletexl opened this issue Jul 8, 2024 · 1 comment

Comments

@deletexl
Copy link

deletexl commented Jul 8, 2024

Hello, I am trying to use Qt6 and OpenVPN3 as libraries for some of my experiments, but I have not been able to make any progress for 2-3 days. Can you tell me where I made a mistake?

First of all, I managed to download the project and build it successfully.

Here's my compile output. Compile all good

demoo@pardus:~/qtproc/Test/3rd$ git clone https://github.com/OpenVPN/openvpn3.git
Cloning into 'openvpn3'...
remote: Enumerating objects: 35895, done.
remote: Counting objects: 100% (10075/10075), done.
remote: Compressing objects: 100% (1781/1781), done.
remote: Total 35895 (delta 8416), reused 9572 (delta 8216), pack-reused 25820
Receiving objects: 100% (35895/35895), 9.44 MiB | 2.37 MiB/s, done.
Resolving deltas: 100% (25969/25969), done.
demoo@pardus:~/qtproc/Test/3rd$ cd openvpn3 && mkdir build && cd build
demoo@pardus:~/qtproc/Test/3rd/openvpn3/build$ cmake -GNinja ..
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/bin/python3 (found version "3.11.2") found components: Interpreter Development Development.Module Development.Embed 
-- Found SWIG: /usr/bin/swig4.0 (found suitable version "4.1.0", minimum required is "3.0")  
-- Found asio: /usr/include  
-- Found lz4: /usr/lib/x86_64-linux-gnu/liblz4.so  
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.11")  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/demoo/qtproc/Test/3rd/openvpn3/build/test/unittests/googletest-download
[1/9] Creating directories for 'googletest'
[2/9] Performing download step (git clone) for 'googletest'
Cloning into 'googletest-src'...
HEAD is now at f8d7d77c Bump version to v1.14 in preparation for release
[3/9] Performing update step for 'googletest'
[4/9] No patch step for 'googletest'
[5/9] No configure step for 'googletest'
[6/9] No build step for 'googletest'
[7/9] No install step for 'googletest'
[8/9] No test step for 'googletest'
[9/9] Completed 'googletest'
-- Found Python3: /usr/bin/python3 (found version "3.11.2") found components: Interpreter 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found xxHash: /usr/include  
-- Found LZO: /usr/lib/x86_64-linux-gnu/liblzo2.so  
lzo found, running lzo compression tests
-- Configuring done
-- Generating done
-- Build files have been written to: /home/demoo/qtproc/Test/3rd/openvpn3/build
demoo@pardus:~/qtproc/Test/3rd/openvpn3/build$ cmake --build .
[1/80] Swig compile ovpncli.i for python
/home/demoo/qtproc/Test/3rd/openvpn3/client/ovpncli.hpp:760: Warning 473: Returning a pointer or reference in a director method is not recommended.
[80/80] Linking CXX executable test/ovpncli/ovpncli
demoo@pardus:~/qtproc/Test/3rd/openvpn3/build$

My project CMakeList.txt

cmake_minimum_required(VERSION 3.16)

project(Test VERSION 0.1 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)

add_subdirectory(3rd/openvpn3) # Here
include_directories(3rd/openvpn3) # Here 1

qt_standard_project_setup()

qt_add_executable(appTest
    main.cpp
)

qt_add_qml_module(appTest
    URI Test
    VERSION 1.0
    QML_FILES
        Main.qml
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(appTest PROPERTIES
#    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appTest
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

target_link_libraries(appTest
    PRIVATE Qt6::Quick
)

include(GNUInstallDirs)
install(TARGETS appTest
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

My project main.cpp


#include <QGuiApplication>
#include <QQmlApplicationEngine>


#include "3rd/openvpn3/client/ovpncli.hpp" // Here1

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/Test/Main.qml"));
    QObject::connect(
        &engine,
        &QQmlApplicationEngine::objectCreationFailed,
        &app,
        []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}

This is the error I get when I try to build my project.

Screenshot from 2024-07-08 08-02-13

I couldn't find an example on exactly how to use this library. There are a few open source projects, but CMakeList files are very complex. Can you help me?

@dsommers
Copy link
Member

dsommers commented Jul 8, 2024

The reference client implementation is in test/ovpncli/cli.cpp. You can also look at how the implementation is done in OpenVPN 3 Linux, for a more comprehensive implementation. The «OpenVPN for Android» Android app also has an OpenVPN 3 integration (in addition to OpenVPN 2.x).

What this library is very picky about is the order of the #include files. The openvpn_io issues are typically an indication of that. Pay attention that when looking at the core-client.hpp from the OpenVPN 3 Linux project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants