使用 tgbot-cpp 的项目无法构建?

问题描述 投票:0回答:1

我在尝试使用 CMake 在 Windows 上构建 C++ 项目时遇到链接器错误。该项目使用 tgbot-cpp 库进行 Telegram 机器人开发。尽管尝试了各种解决方案,但我仍无法解决这些错误。

这是我的 CMakeLists.txt 文件的片段:

cmake_minimum_required(VERSION 3.10.2)
project(todolistbot)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(Boost_USE_MULTITHREADED ON)

find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Boost COMPONENTS system REQUIRED)
find_package(CURL)
include_directories(${OPENSSL_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
if (CURL_FOUND)
    include_directories(${CURL_INCLUDE_DIRS})
    add_definitions(-DHAVE_CURL)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTGBOT_DISABLE_NAGLES_ALGORITHM -DTGBOT_CHANGE_SOCKET_BUFFER_SIZE -DTGBOT_CHANGE_READ_BUFFER_SIZE")

add_executable(todolistbot main.cpp
        keyboards.h)

# Link against Boost.Asio, OpenSSL, Threads, CURL, and ws2_32 library
target_link_libraries(todolistbot
        PRIVATE
        ${CMAKE_THREAD_LIBS_INIT}
        ${OPENSSL_LIBRARIES}
        ${Boost_LIBRARIES}
        ${CURL_LIBRARIES}
        ws2_32
        C:/Users/menshutkin/.vcpkg-clion/vcpkg/installed/x64-windows/lib/TgBot.lib)

这是我遇到的链接器错误的示例:

C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: CMakeFiles/todolistbot.dir/main.cpp.obj: in function `operator()':
D:/C++_pj/todolistbot/main.cpp:11: undefined reference to `TgBot::Api::sendMessage(boost::variant<long long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int, std::shared_ptr<TgBot::GenericReply>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::vector<std::shared_ptr<TgBot::MessageEntity>, std::allocator<std::shared_ptr<TgBot::MessageEntity> > > const&, bool, bool, int) const'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: D:/C++_pj/todolistbot/main.cpp:16: undefined reference to `StringTools::startsWith(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: D:/C++_pj/todolistbot/main.cpp:19: undefined reference to `TgBot::Api::sendMessage(boost::variant<long long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, int, std::shared_ptr<TgBot::GenericReply>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::vector<std::shared_ptr<TgBot::MessageEntity>, std::allocator<std::shared_ptr<TgBot::MessageEntity> > > const&, bool, bool, int) const'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: CMakeFiles/todolistbot.dir/main.cpp.obj: in function `main':
D:/C++_pj/todolistbot/main.cpp:7: undefined reference to `TgBot::Bot::_getDefaultHttpClient()'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: D:/C++_pj/todolistbot/main.cpp:7: undefined reference to `TgBot::Bot::Bot(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, TgBot::HttpClient const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: D:/C++_pj/todolistbot/main.cpp:23: undefined reference to `TgBot::Api::getMe() const'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: D:/C++_pj/todolistbot/main.cpp:24: undefined reference to `TgBot::TgLongPoll::TgLongPoll(TgBot::Bot const&, int, int, std::shared_ptr<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > const&)'
C:\Program Files\JetBrains\CLion 2023.2.2\bin\mingw\bin/ld.exe: D:/C++_pj/todolistbot/main.cpp:27: undefined reference to `TgBot::TgLongPoll::start()'
collect2.exe: error: ld returned 1 exit status

我已经检查了我的库链接,确保通过 vcpkg 正确安装了库,验证了库路径,并设置了正确的包含目录。尽管做出了这些努力,我仍然面临这些链接器错误。

任何有关如何解决此问题的见解或建议将不胜感激。谢谢!

c++ windows telegram-bot clion
1个回答
0
投票

兄弟,你这个问题解决了吗?

© www.soinside.com 2019 - 2024. All rights reserved.