Reputation: 3791
In visual studio 2010, I get
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Server::Server(class boost::asio::io_service &)" (??0Server@@QAE@AAVio_service@asio@boost@@@Z) referenced in the function _main C:\Users\Lucie\Documents\Visual Studio 2010\Projects\Expérimentation Serveur\Expérimentation Serveur\Main_Serveur.obj
However, I have the class definition in the header file and the class implementation in the .cpp file both included in the solution, so I really don't see why I'm getting this. Furthermore, I have checked, and the definition and declaration seem to match.
Here is 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;
}
Here is 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
And here is the relevant part of 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();
}
Any help would be greatly appreciated.
Upvotes: 0
Views: 620
Reputation: 91
It must because of you wouldn't have compiled Server.cpp. Instead you compiled Main_serveur.cpp file only. This time the linker does not see the Server.obj and this pops up link error like you've gotten (undefined copy constructor). You either create project add all files to it (like you did) or compile cpp files which are left to be compiled separatley to generate its objs. Also, you could use makefile, which is better than the other two options.
Upvotes: 0
Reputation: 3791
Ended up creating a new project and including the sources and headers, and the project compiled. Oh well.
Upvotes: 2