Re: multiple definition of `__' ???
On Jan 26, 12:10 pm, Rolf Magnus <ramag...@t-online.de> wrote:
mike wrote:
I am writing some c++ code and have been stuck in the linking
process. I get an error of multiple definition of `__' when linking.
I would post this in the gcc usenet, but I think it is more of a c++
syntax problem than a linker problem. Here is my setup, I have a
class which is divided into a header and a source file, the source
file includes the header for the class (like it should). I then have
another source file that includes my main function. This source file
also includes the header for the class. The header file has the
proper
#ifndef SOMETHING_H
#define SOMETHING_H
............
#endif
but when I link, I get the error:
obj/something.o:(.bss+0x0): multiple definition of `__'
obj/main.o:(.bss+0x0): first defined here
if I take out the include of "something.h" in my main.cpp, and any
class instances, then it all links just fine.
Any ideas what I am missing?
Not without seeing more of your code. In the three lines you provided and in
your description, there is no error. Post a minimal, but complete program
that shows the error.
Well, I was hoping I could get it fixed without having to post too
much code, but here goes:
test0.cpp******************************
#include "rover_server.h"
#include <fcntl.h>
#include <cerrno>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <map>
static void init_sockaddr(const char * addr, uint16_t port, sockaddr &
sa) {
sockaddr_in & ret = (sockaddr_in&) sa;
ret.sin_family = AF_INET;
ret.sin_port = htons(port);
if (!inet_aton(addr, &ret.sin_addr))
throw "error in init_sockaddr";
memset(ret.sin_zero, 0, sizeof(ret.sin_zero));
}
int main(int argc, char* argv[]) {
// Set up the map for the backbones
std::map<int, int> backbones0;
// Set up the two backbones.
int backbone0 = socket(AF_INET, SOCK_DGRAM, 0);
fcntl(backbone0, F_SETFL, O_NONBLOCK);
sockaddr backbone1_addr;
init_sockaddr("0.0.0.0", 5112, backbone1_addr);
connect(backbone0, &backbone1_addr, sizeof(backbone1_addr));
backbones0[1] = backbone0;
// Setup the two server sockets
int server0 = socket(AF_INET, SOCK_STREAM, 0);
fcntl(server0, F_SETFL, O_NONBLOCK);
sockaddr server0_addr;
init_sockaddr("0.0.0.0", 5113, server0_addr);
bind(server0, &server0_addr, sizeof(server0_addr));
listen(server0, 10);
RoverServer rover0 = RoverServer(server0, backbones0, 0);
}
rover_server.h ***********************************
#ifndef ROVER_SERVER_H
#define ROVER_SERVER_H
#include "ev_cpp.h"
#include "rover_message.h"
#include <fcntl.h>
#include <unistd.h>
#include <cerrno>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <map>
typedef int socketfd;
class RoverServer {
private:
std::map<int, socketfd> backbones;
std::map<int, socketfd> clients;
int id;
public:
// Default constructor
RoverServer(socketfd serverfd, std::map<int, socketfd> b, int i);
// Callback Methods for EV
void server_cb(ev::io& watcher, int revents);
void client_cb(ev::io& watcher, int revents);
void backbone_cb(ev::io& watcher, int revents);
};
#endif
rover_server.cpp (not the whole
file)***********************************
#include "rover_server.h"
// Constructor
RoverServer::RoverServer(socketfd serverfd, std::map<int, socketfd> b,
int i) : backbones(b), id(i) {
// Setup the listening socket
ev_default_loop(0);
// Setup the main watcher for libev
ev::io server_watcher;
server_watcher.set<RoverServer, &RoverServer::server_cb>(this);
server_watcher.set(serverfd, EV_READ);
..
..
..
..
Thanks for the help, hopefully this will make it easier to help.