添加新库时出现重复符号错误

Duplicate symbol error adding new library

在 ns-3 环境中工作,我制作了一个库,其中有一些在我的代码中调用的方法。为了编译库,我在 wscript 文件中添加了 link 到库中,我控制它是否已经定义如下:

#ifndef MY_LIBRARY_H_
#define MY_LIBRARY_H_

.. my methods

#endif

当我构建代码时,生成了以下错误:

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)

我认为这是因为我在不止一个地方使用了我的方法 class 并且可能在多次编译时出现了一些错误。有解决问题的想法吗? (我不是专家,也许我漏掉了什么!!!)

感谢帮助!!

[编辑]

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

你的函数findOutSector是直接写在header里面的吗?如果是,将定义放在 .c 文件中(+ compile & link),并将函数声明放在 header 中。该函数应该在所有已编译的 objects 中只存在一次,并且声明用作对它的引用。