multiple definition of `__' ???

Discussion in 'C++' started by mike, Jan 26, 2008.

  1. mike

    mike Guest

    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?
     
    mike, Jan 26, 2008
    #1
    1. Advertising

  2. mike

    Rolf Magnus Guest

    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.
     
    Rolf Magnus, Jan 26, 2008
    #2
    1. Advertising

  3. mike

    mike Guest

    On Jan 26, 12:10 pm, Rolf Magnus <> 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.
     
    mike, Jan 26, 2008
    #3
  4. mike schrieb:

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

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

    --
    "PS: Ein Realname wäre nett. Ich selbst nutze nur keinen, weil mich die
    meisten hier bereits mit Namen kennen." -- Markus Gronotte aka Makus /
    Kosst Amojan / maqqusz / Mr. G / Ferdinand Simpson / Quartillia
    Rosenberg in dse <45608268$0$5719$-online.net>
     
    Johannes Bauer, Jan 27, 2008
    #4
  5. mike

    James Kanze Guest

    On Jan 26, 9:13 pm, mike <> wrote:
    > On Jan 26, 12:10 pm, Rolf Magnus <> 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:


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

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jan 27, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jianli Shen
    Replies:
    1
    Views:
    645
    Victor Bazarov
    Mar 13, 2005
  2. Ark
    Replies:
    1
    Views:
    453
    Chris Torek
    Aug 7, 2004
  3. Jon Slaughter
    Replies:
    4
    Views:
    473
    Jon Slaughter
    Oct 26, 2005
  4. Replies:
    11
    Views:
    1,275
    Ian Collins
    Aug 5, 2006
  5. Pierre Yves
    Replies:
    2
    Views:
    526
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page