Search code examples
c++ns-3

Duplicate symbol error adding new library


working in the ns-3 environment, I have made a library where there are some methods called in my code. In order to compile the library I add in the wscript file the link to the library and I control if it is already define as follow:

#ifndef MY_LIBRARY_H_
#define MY_LIBRARY_H_

.. my methods

#endif

When I build the code this following error is generated:

duplicate symbol __Z8getValueiib in:
    src/model/bs-phy.cc.1.o
    src/model/ue-phy.cc.1.o
ld: 3 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I think this is due to the fact that I use my methods in more then one class and maybe there are some error for multi-compiling. Any idea to solve the problems? (I'm not an expert and maybe I'm missing something!!!)

Thanks for the help!!

[EDIT]

uint32_t findOutSector()
{
    uint32_t sector = 0;
    return sector;
}

Solution

  • Is your function findOutSector written in the header directly? If yes, put the definition in a .c file (+ compile & link) and just the function declaration in the header. The function should just exist once in all compiled objects and the declaration serves as reference to it.