multiple definition of `__' ???

M

mike

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?
 
R

Rolf Magnus

mike said:
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.
 
M

mike

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.
 
J

Johannes Bauer

mike said:
rover_server.cpp (not the whole
file)***********************************

What part of "minimal, but complete" did you not understand, exactly?
Your code is neither minimal (not at all), nor is it complete.

It is IMHO highly likely that when you try to find a *minimal* example
of code that fails (by removing more and more code), you'll find the
error by yourself.

Greetings,
Johannes
 
J

James Kanze

Well, I was hoping I could get it fixed without having to post too
much code, but here goes:

What you've posted isn't really minimal, but...

It can't be the source of your problem, because there's no
symbol "__" in it. If this code actually causes the problem,
then the problem is in one of the headers you've included, but
haven't posted. In your case, I'd start by searching my own
files (all of them) for the sequence "__"---no legal user name
can contain this, so if you find it, you've got an error right
there. If you don't, then there is a problem in your system
includes and/or libraries somewhere, and you'll have to ask in
some group dedicated to your system. (One trick for finding out
where: run your sources through the pre-processor, then see
where __ is defined. Note that the sequence __ is legal in
system headers, however, and that just naively searching for it
will result in a lot of output---you'll need to search for it as
a complete symbol: "\<__\>" with grep, for example.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top