私はC++でこのエラーを受け取りました、そして私は本当にそれの底に到達する方法を知りません:
g++ proxy.cpp -lboost_thread -lboost_filesystem -lboost_system
/tmp/ccUHa2s3.o:関数 `main'内:proxy.cpp:(。text + 0x1d8):`
server::server(std::deque<boost::shared_ptr<boost::asio::io_service>, std::allocator<boost::shared_ptr<boost::asio::io_service> > > const&, int)
'への未定義の参照collect2:ldが1つの終了ステータスを返しました
私は次のソースコードを持っています(http://alexott.net/common/asio-proxy-async/proxy-conn.cpp.htmlからコピーしました):
//proxy.cpp:
#include "proxy-server.hpp"
int main(int argc, char** argv) {
try {
int thread_num=2;
if(argc > 1)
thread_num=boost::lexical_cast<int>(argv[1]);
ios_deque io_services;
std::deque<ba::io_service::work> io_service_work;
boost::thread_group thr_grp;
for (int i = 0; i < thread_num; ++i) {
io_service_ptr ios(new ba::io_service);
io_services.push_back(ios);
io_service_work.push_back(ba::io_service::work(*ios));
thr_grp.create_thread(boost::bind(&ba::io_service::run, ios));
}
server server(io_services); //apparently there's some error here?
thr_grp.join_all();
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
//proxy-server.hpp:
#ifndef _PROXY_SERVER_H
#define _PROXY_SERVER_H 1
#include "common.h"
#include "proxy-conn.hpp"
#include <deque>
typedef std::deque<io_service_ptr> ios_deque;
class server {
public:
server(const ios_deque& io_services, int port=10001);
private:
void start_accept();
void handle_accept(connection::pointer new_connection, const bs::error_code& error);
ios_deque io_services_;
ba::ip::tcp::acceptor acceptor_;
};
#endif /* _PROXY-SERVER_H */
//proxy-server.cpp:
#include "proxy-server.hpp"
server::server(const ios_deque& io_services, int port)
: io_services_(io_services),
acceptor_(*io_services.front(), ba::ip::tcp::endpoint(ba::ip::tcp::v4(), port)) {
start_accept();
}
void server::start_accept() {
// Round robin.
io_services_.push_back(io_services_.front());
io_services_.pop_front();
connection::pointer new_connection = connection::create(*io_services_.front());
acceptor_.async_accept(new_connection->socket(),
boost::bind(&server::handle_accept, this, new_connection,
ba::placeholders::error));
}
void server::handle_accept(connection::pointer new_connection, const bs::error_code& error) {
if (!error) {
new_connection->start();
start_accept();
}
}
誰かがこのエラーを修正する方法について正しい方向に私を向けることができますか?
編集
次のエラーが発生します。
g++ proxy.cpp proxy-server.cpp -lboost_thread -lboost_filesystem -lboost_system
/tmp/ccl3DHn7.o:関数内 `
server::handle_accept(boost::shared_ptr<connection>, boost::system::error_code const&)
':proxy-server.cpp:(。text + 0x250):`connection::start()
'への未定義の参照/tmp/ccl3DHn7.o:関数内 `connection::create(boost::asio::io_service&)
':proxy-server.cpp:(。 text._ZN10connection6createERN5boost4asio10io_serviceE [connection :: create(boost :: asio :: io_service&)] + 0x29): `connection::connection(boost::asio::io_service&)
'collect2への未定義の参照:ldは1つの終了ステータス`を返しました