Skip to content

The echo UDP server example does not compile against package installed by vcpkg. #293

Open
@denismakogon

Description

@denismakogon

CMakeLists.txt:

cmake_minimum_required (VERSION 3.24)

project (udplib LANGUAGES C CXX VERSION 0.0.1 DESCRIPTION "udplib")

set (CMAKE_CXX_STANDARD 20)

add_executable(${PROJECT_NAME} src/main.cc ${HEADERS})

find_package(unofficial-evpp CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE unofficial::evpp::evpp_static)

code:

#include <stdio.h>

#include <evpp/udp/udp_message.h>
#include <evpp/event_loop.h>
#include <evpp/event_loop_thread_pool.h>

int main(int argc, char* argv[]) {
    std::vector<int> ports = { 1053, 5353 };
    int port = 29099;
    int thread_num = 2;

    if (argc > 1) {
        if (std::string("-h") == argv[1] ||
            std::string("--h") == argv[1] ||
            std::string("-help") == argv[1] ||
            std::string("--help") == argv[1]) {
            std::cout << "usage : " << argv[0] << " <listen_port> <thread_num>\n";
            std::cout << " e.g. : " << argv[0] << " 8080 24\n";
            return 0;
        }
    }

    if (argc == 2) {
        port = atoi(argv[1]);
    }
    ports.push_back(port);

    if (argc == 3) {
        port = atoi(argv[1]);
        thread_num = atoi(argv[2]);
    }

    evpp::udp::Server server;
    server.SetThreadDispatchPolicy(evpp::ThreadDispatchPolicy::kIPAddressHashing);
    server.SetMessageHandler([](evpp::EventLoop* loop, evpp::udp::MessagePtr& msg) {
        std::stringstream oss;
        oss << "func=" << __FUNCTION__ << " OK"
            << " body=" << std::string(msg->data(), msg->size()) << "\n";
        evpp::udp::SendMessage(msg);
    });
    server.Init(ports);
    server.Start();

    evpp::EventLoop loop;
    std::shared_ptr<evpp::EventLoopThreadPool> tpool(new evpp::EventLoopThreadPool(&loop, thread_num));
    tpool->Start(true);
    server.SetEventLoopThreadPool(tpool);
    loop.Run();
    server.Stop(true);
    tpool->Stop(true);
    return 0;
}

errors:

[ 50%] Building CXX object CMakeFiles/udplib.dir/src/main.cc.o
/Users/denismakogon/go/src/github.com/denismakogon/udplib/src/main.cc:33:16: error: no type named 'Server' in namespace 'evpp::udp'
    evpp::udp::Server server;
    ~~~~~~~~~~~^
/Users/denismakogon/go/src/github.com/denismakogon/udplib/src/main.cc:34:42: error: no member named 'ThreadDispatchPolicy' in namespace 'evpp'
    server.SetThreadDispatchPolicy(evpp::ThreadDispatchPolicy::kIPAddressHashing);
                                   ~~~~~~^
2 errors generated.
make[2]: *** [CMakeFiles/udplib.dir/src/main.cc.o] Error 1
make[1]: *** [CMakeFiles/udplib.dir/all] Error 2
make: *** [all] Error 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions