LNK 2019使用Boost::asio时出错

LNK 2019 error using Boost::asio

本文关键字:asio 出错 Boost 2019 使用 LNK      更新时间:2023-10-16

我只是想测试我朋友的一段代码,如下所示:

#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <iostream>
#include <sstream>
#include <string>
boost::asio::io_service io;
std::string port;
boost::asio::serial_port_base::baud_rate baud(115200);
int main() {
    std::cout << "Enter port number: ";
    std::getline(std::cin,port);
    while(port.empty()) {
        std::cout << std::endl;
        std::cout << "Error: The user must provide a port number." << std::endl;
        std::cout << "Enter port number (Example: COM5): ";
        std::getline(std::cin,port);
    }
    std::cout << std::endl;
    return 0;
}

在VC++目录中,我链接了Include和64位库。

在Linker->Input中,我添加了额外的依赖项。

每当我运行此代码时,我都会收到错误:

错误1错误LNK2019:未解析的外部符号"class boost::system::Error_category const&__cdecl boost:;system::system_categor(void)"(?system_category@system@助推@@YAABVerror_category@12@XZ)在函数"public:__thiscall boost::system::error_code::error-code(void)"中引用(??0error_code@system@助推@@QAE@XZ)C:\Users\Bilal\Documents\Visual Studio 2012\Projects\Serial\ Serial\main.obj Serial

错误2错误LNK2019:未解析的外部符号"class boost::system::Error_category const&__cdecl boost:;system::generic_categor(void)"(?generic_category@system@助推@@YAABVerror_category@12@XZ)在函数"void __cdecl boost::system::`errno_ecat''(void)的动态初始值设定项"(??__Eerrno_ecat@system@boost@@YAXXZ)C:\Users\Bilal\Documents\Visual Studio 2012\Projects\Serial\main.obj Serial

有人能告诉我出了什么问题吗?

您需要指定库的路径(Linker->其他库目录,然后输入boost库所在的位置),或者将库添加到系统库路径(在linux中)/sys路径(在windows中)。