【问题标题】:Cannot compile LibOTR无法编译 LibOTR
【发布时间】:2015-03-31 16:38:31
【问题描述】:

我正在尝试使用libotr,但在尝试编译非常基本的库初始化时遇到以下问题。

#include <libotr/proto.h>

int main(int argc, char const *argv[])
{
  OTRL_INIT;
  // OtrlUserState userstate = otrl_userstate_create();

  return 0;
}

我正在使用以下命令编译它:

g++ main.cpp -o main -L /usr/local/lib/ -lotr

但由于某种原因,我得到了:

Undefined symbols for architecture x86_64:
  "otrl_init(unsigned int, unsigned int, unsigned int)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bin/bin] Error 1

我明确检查过,该库确实有以下符号。

【问题讨论】:

    标签: c++ c symbols name-mangling


    【解决方案1】:

    经过快速观察,我注意到 libotr 正在使用 C 类型名称重整,只需在库的 include 子句中添加以下行即可解决问题:

    extern "C" {
      #include <libotr/proto.h>
    }
    

    如果您有类似的问题,只需使用 nm 实用程序列出库的符号并检查符号名称是否以一个或两个下划线开头:_fooC 样式,而 __foo 是 @987654328 @风格。

    附注我发布了这个,因为我花了一段时间才弄清楚。我希望这个问题+答案可以为您节省一些时间。

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 2015-06-07
      • 2013-03-06
      • 2016-08-24
      • 2018-10-18
      • 2014-02-16
      • 2015-10-29
      • 1970-01-01
      • 2013-01-29
      相关资源
      最近更新 更多