Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Boost Asio在Eclipse Cdt中不链接?_C++_Boost_Boost Asio_Linker Errors - Fatal编程技术网

C++ Boost Asio在Eclipse Cdt中不链接?

C++ Boost Asio在Eclipse Cdt中不链接?,c++,boost,boost-asio,linker-errors,C++,Boost,Boost Asio,Linker Errors,我读过其他Stackoverflow线程,但似乎没有一个解决方案有帮助 我无法在EclipseCDT中链接Boost Asio库。但是,我可以链接其他库,这使我认为Eclipse不是问题所在 我在徐本图14.04。Boost安装时附带:sudo apt get install libboost all dev。 这是/usr/include/: 这是/usr/include/boost: 这是Eclipse Cdt链接器: 这是我试图编译的代码: //===================

我读过其他Stackoverflow线程,但似乎没有一个解决方案有帮助

我无法在EclipseCDT中链接Boost Asio库。但是,我可以链接其他库,这使我认为Eclipse不是问题所在

我在徐本图14.04。Boost安装时附带:
sudo apt get install libboost all dev
。 这是
/usr/include/

这是
/usr/include/boost

这是Eclipse Cdt链接器:

这是我试图编译的代码:

//============================================================================
// Name        : BoostMain.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include <ostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>

int do_get(std::string &host_, std::string &port_, std::string url_path,
        std::ostream &out_, std::vector<std::string> &headers,
        unsigned int timeout) {

    try {
        using namespace boost::asio::ip;
        tcp::iostream request_stream;
        if (timeout > 0) {
            request_stream.expires_from_now(
                    boost::posix_time::milliseconds(timeout));
        }
        request_stream.connect(host_, port_);
        if (!request_stream) {
            return -1;
        }
        request_stream << "GET " << url_path << " HTTP/1.0\r\n";
        request_stream << "Host: " << host_ << "\r\n";
        request_stream << "Accept: */*\r\n";
        request_stream << "Cache-Control: no-cache\r\n";
        request_stream << "Connection: close\r\n\r\n";
        request_stream.flush();
        std::string line1;
        std::getline(request_stream, line1);
        if (!request_stream) {
            return -2;
        }
        std::stringstream response_stream(line1);
        std::string http_version;
        response_stream >> http_version;
        unsigned int status_code;
        response_stream >> status_code;
        std::string status_message;
        std::getline(response_stream, status_message);
        if (!response_stream || http_version.substr(0, 5) != "HTTP/") {
            return -1;
        }
        if (status_code != 200) {
            return (int) status_code;
        }
        std::string header;
        while (std::getline(request_stream, header) && header != "\r")
            headers.push_back(header);
        out_ << request_stream.rdbuf();
        return status_code;
    } catch (std::exception &e) {
        std::cout << e.what() << std::endl;
        return -3;
    }

    return -1;

}

int main() {
    std::cout << "Hello World" << std::endl;
//  std::string host, port;
//  std::vector<std::string> headers;
//  std::string url = "https://www.google.com/";
//  int output = do_get(host, port, url, std::cout, headers, 1000);
//  std::cout << "Out:" << output << std::endl << std::endl;
//  std::cout << host << std::endl << port << std::endl << std::endl;
    //std::cout << stream;
    return 0;
}

Boost肯定已安装,因为尝试重新安装Boost会导致“libboost all dev已是最新版本”。解决此问题的最佳方法是什么?

没有用于
Boost\u asio的库。
boost::asio
命名空间中的所有内容都在头中实现。您可能需要链接到其他Boost库,例如
Boost\u system
(我看到您已经有了)

您应该从项目中删除
boost\u asio
的链接配置

boost\u asio
可能需要的库是。你可能还想读书

   **** Build of configuration Debug for project BoostMain ****

    make all 
    Building file: ../src/BoostMain.cpp
    Invoking: GCC C++ Compiler
    g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/BoostMain.d" -MT"src/BoostMain.d" -o "src/BoostMain.o" "../src/BoostMain.cpp"
    Finished building: ../src/BoostMain.cpp

    Building target: BoostMain
    Invoking: GCC C++ Linker
    g++ -L/usr/include -o "BoostMain"  ./src/BoostMain.o   -lboost_system -lboost_thread -lboost_asio
    /usr/bin/ld: cannot find -lboost_asio
    collect2: error: ld returned 1 exit status
    make: *** [BoostMain] Error 1

    **** Build Finished ****