Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

c++ - LNK 2019 error using Boost::asio

I am just trying to test a snippet of my friends code which goes like:

#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;
}

In the VC++ directories I have linked both the Include and the 64 bit libraries.

In Linker -> Input I have put additional dependencies.

Whenever I run this code I get the error:

Error 1 error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "public: __thiscall boost::system::error_code::error_code(void)" (??0error_code@system@boost@@QAE@XZ) C:UsersBilalDocumentsVisual Studio 2012ProjectsSerialSerialmain.obj Serial

and

Error 2 error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'errno_ecat''(void)" (??__Eerrno_ecat@system@boost@@YAXXZ) C:UsersBilalDocumentsVisual Studio 2012ProjectsSerialSerialmain.obj Serial

Can anyone tell me what's going wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need specify the path of the lib(Linker->additional library directories, then input where your boost lib is), or add the library to the system library path(in linux)/sys path(in windows).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...