【问题标题】:GCC doesn't link static library dependency (makefile)GCC 不链接静态库依赖项(makefile)
【发布时间】:2016-01-16 04:08:35
【问题描述】:

我使用一个静态库,假设我已经构建并安装到 /usr/local/lib 的 cityhash。我有一个使用 cityhash 的文件 foo.cxx,例如:

// foo.cxx
u64 get_hash(const std::string &s) {
  return CityHash64(s.data(), s.size());
}

我用它构建了一个静态库:

gcc -c foo.cxx  => foo.o
ar rcs libfoo.a foo.a  => libfoo.a

我有另一个文件 bar.cxx,它使用 foo.cxx 和间接使用 CityHash 函数。我编译它,并与 libcityhash.a 和 libfoo.a 链接,如下所示:

gcc -c bar.cxx  => bar.o
gcc -L. -o bar bar.o -lcityhash -lfoo

但这不起作用,链接器抱怨 CityHash64 是未定义的引用。怎么了?当我不创建静态库 libfoo.a 时,一切正常。

【问题讨论】:

    标签: c++ gcc makefile linker


    【解决方案1】:

    看到这个。您需要编写链接器参数-lfoo -lcityhash。需要符号的库应该放在提供符号的库之前。

    Why does the order in which libraries are linked sometimes cause errors in GCC?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多