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

Problems with dependencies (Boost) in cmake + vcpkg on Windows #1075

Open
sairus7 opened this issue Nov 17, 2022 · 1 comment
Open

Problems with dependencies (Boost) in cmake + vcpkg on Windows #1075

sairus7 opened this issue Nov 17, 2022 · 1 comment

Comments

@sairus7
Copy link

sairus7 commented Nov 17, 2022

I'm trying to run this code from this example on Windows with vscode + cmake + vcpkg:

ws-client.cpp
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
 
#include <iostream>
#include <string>
 
typedef websocketpp::client<websocketpp::config::asio_client> client;
 
int main() {
    bool done = false;
    std::string input;
 
    while (!done) {
        std::cout << "Enter Command: ";
        std::getline(std::cin, input);
 
        if (input == "quit") {
            done = true;
        } else if (input == "help") {
            std::cout
                << "\nCommand List:\n"
                << "help: Display this help text\n"
                << "quit: Exit the program\n"
                << std::endl;
        } else {
            std::cout << "Unrecognized Command" << std::endl;
        }
    }
 
    return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(wspp VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(ws-client ws-client.cpp)

find_package(websocketpp CONFIG REQUIRED)

target_link_libraries(ws-client PRIVATE 
    websocketpp::websocketpp
)

vcpkg.json
{
    "name": "wspp",
    "version": "1.0.1",
    "dependencies": [
        "websocketpp"
	  ]
}

With mingw (GCC 11.2.0 x86_64-64-mingw32) compiler I have the following error:

[build] In file included from I:/code/test_websocketpp/build/vcpkg_installed/x64-windows/include/websocketpp/concurrency/basic.hpp:31,
[build]                  from I:/code/test_websocketpp/build/vcpkg_installed/x64-windows/include/websocketpp/config/core_client.hpp:38,
[build]                  from I:/code/test_websocketpp/build/vcpkg_installed/x64-windows/include/websocketpp/config/asio_no_tls_client.hpp:31,
[build]                  from I:/code/test_websocketpp/ws-client.cpp:1:
[build] I:/code/test_websocketpp/build/vcpkg_installed/x64-windows/include/websocketpp/common/thread.hpp:63:14: fatal error: boost/thread.hpp: No such file or directory
[build]    63 |     #include <boost/thread.hpp>
[build]       |              ^~~~~~~~~~~~~~~~~~

With MSVC I have the following error:

[build] I:\code\test_websocketpp\build\vcpkg_installed\x86-windows\include\websocketpp/common/random.hpp(59,18): fatal error C1083: Cannot open include file: 'boost/random/uniform_int_distribution.hpp': No such file or directory [I:\code\test_websocketpp\build\ws-client.vcxproj]

Both seems to be lacking some boost files.
So I've added entire boost to my vcpkg.json and wait for it to install and now my build folder is of 1GB size...

Thois solved problem with MSVC, but next mingw error was undefined reference to '__imp_WSAStartup', so I linked ws2_32 library.

Final version worked for me with both compilers:

CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(wspp VERSION 0.1.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(ws-client ws-client.cpp)

find_package(websocketpp CONFIG REQUIRED)

target_link_libraries(ws-client PRIVATE 
    websocketpp::websocketpp
)

target_link_libraries(ws-client PRIVATE ws2_32)
vcpkg.json
{
    "name": "wspp",
    "version": "1.0.1",
    "dependencies": [
        "websocketpp",
        "boost"
	  ]
}

Is there a simpler way to compile the same example?

@wilricknl
Copy link

You can add the following line above your websockets includes:

#define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_

I am not sure if there's some define to use C++11 definitions by default. I suspect there is, but this was the quick fix for now.

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