2

我正在尝试编译和链接 Verilator (veripool.org) 的运行时支持代码。它构建得很好,但由于某种原因,有一些方法没有出现在相关的目标文件中,Verilated::timeunit(int)并且Verilated::timeprecision(int).

这些表面上是在 include/verilated.h 中定义的:

    static int timeunit() VL_MT_SAFE { return Verilated::threadContextp()->timeunit(); }
    static int timeprecision() VL_MT_SAFE { return Verilated::threadContextp()->timeprecision(); }

现在,您可以看到调用函数中两种类型的方法都有一个参数,该参数int显示在链接步骤中:

ld: /home/jon/controlix/src/nuttx/nuttx/staging/libcontrols.a(Vhello_world__ALL.o): in function `Vhello_world::__Vconfigure(Vhello_world__Syms*, bool)':
Vhello_world__ALL.cpp:(.text+0x15): undefined reference to `Verilated::timeunit(int)'
Vhello_world__ALL.cpp:(.text+0x15): relocation truncated to fit: R_X86_64_PLT32 against undefined symbol `Verilated::timeunit(int)'
ld: Vhello_world__ALL.cpp:(.text+0x20): undefined reference to `Verilated::timeprecision(int)'
Vhello_world__ALL.cpp:(.text+0x20): relocation truncated to fit: R_X86_64_PLT32 against undefined symbol `Verilated::timeprecision(int)'
l

我尝试将方法声明更改verilated.h为将 int 作为参数,即使缺少该参数会导致编译时错误,但是这两个方法声明仍然没有出现在verilated.cpp. 类中的其他方法Verilated::显示得很好。

我错过了什么?

4

1 回答 1

3

为什么在头文件中定义为静态的 C++ 方法未显示在符号表中

编辑:最初,我假设这些是非成员函数,例如您的报价。查看源代码,我发现它们是成员函数。但我还发现:

#ifndef VL_NO_LEGACY
    // Deprecated
    static int timeunit() VL_MT_SAFE { return Verilated::threadContextp()->timeunit(); }
    static int timeprecision() VL_MT_SAFE { return Verilated::threadContextp()->timeprecision(); }

如果定义了宏VL_NO_LEGACY,则不会定义或声明这些函数。这可以解释缺乏他们的符号。


Verilated::timeunit(int)Verilated::timeprecision(int)

这些表面上是在 include/verilated.h 中定义的:

static int timeunit() VL_MT_SAFE { return Verilated::threadContextp()->timeunit(); }
static int timeprecision() VL_MT_SAFE { return Verilated::threadContextp()->timeprecision(); }

不,这些绝对不是上面声明的函数的定义。注意不同的参数列表。


即使缺少它会导致编译时错误

不必要。的定义static int timeunit()不会妨碍 的声明Verilated::timeunit(int)

于 2021-07-18T17:39:28.237 回答