在视觉工作室 2010 中,我得到
错误1错误LNK2019:函数中引用的未解析外部符号“public:__thiscall Server::Server(class boost::asio::io_service &)”(??0Server@@QAE@AAVIo_service@asio@boost@@@Z) _main C:\Users\Lucie\Documents\Visual Studio 2010\Projects\Expérimentation Serveur\Exérimentation Serveur\Main_Serveur.obj
但是,我的头文件中的类定义和 .cpp 文件中的类实现都包含在解决方案中,所以我真的不明白为什么会这样。此外,我已经检查过,定义和声明似乎匹配。
这是 Main_Serveur.cpp:
include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <hash_map>
#include <functional>
#include <boost/bind.hpp>
#include <algorithm>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/asio.hpp>
#include <hash_set>
#include "Connection.h"
#include "Server.h"
using boost::asio::ip::tcp;
int main()
{
try
{
boost::asio::io_service io_service;
Server server(io_service);
io_service.run();
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
std::cin.get();
return 0;
}
这是Server.h:
#ifndef __SERVER_H__
#define __SERVER_H__
#include"Connection.h"
#include<boost\bind.hpp>
#include<boost\asio.hpp>
#include<boost\shared_ptr.hpp>
#include<boost\enable_shared_from_this.hpp>
#include<hash_set>
#include<string>
using boost::asio::ip::tcp;
class Connection;
class Server : public boost::enable_shared_from_this<Server>
{
public:
Server(boost::asio::io_service & io_service);
void removeSocketFromList(tcp::socket * socketToRemove);
void sendToList(std::string message);
void addSocketToList(tcp::socket * newSocket);
private:
void start_accept();
void handle_accept
(
boost::shared_ptr<Connection> new_connection,
const boost::system::error_code& error
);
std::hash_set<tcp::socket*> sockets_;
tcp::acceptor acceptor_;
};
#endif
这是 Server.cpp 的相关部分:
#include"Server.h"
#include"Connection.h"
#include<boost\asio.hpp>
#include<hash_set>
using boost::asio::ip::tcp;
Server::Server(boost::asio::io_service & io_service):
acceptor_(io_service, tcp::endpoint(tcp::v4(), 13))
{
start_accept();
}
任何帮助将不胜感激。