c++ - 未定义对 'uuid_generate' 的引用,即使我使用 -luuid

标签 c++ uuid

<分区>

我的测试.cpp

#include <uuid/uuid.h>
#include <iostream>

int main(int argc, char *argv[])
{
  uuid_t id;
  uuid_generate(id);

  char *string = new char[100];
  uuid_unparse(id, string);

  std::cout << string << std::endl;

  return 0;
}

我正在使用 Ubuntu 14

我正在运行我的 test.cpp 作为...

g++ -luuid test.cpp

和输出

test.cpp:(.text+0x26): undefined reference to `uuid_generate'
test.cpp:(.text+0x47): undefined reference to `uuid_unparse'
collect2: error: ld returned 1 exit status

我的 g++ 版本:

Target: x86_64-linux-gnu
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)

而且我已经安装了 uuid-dev。

sudo apt-get install uuid uuid-dev

uuid is already the newest version.
uuid-dev is already the newest version.

最佳答案

链接库的顺序很重要,您需要在引用它的模块之后添加 -luuid:

g++ test.cpp -luuid

除非您使用分组选项(-Wl,--start-group,-Wl,--end-group)。

另见 this answer了解更多详情。

关于c++ - 未定义对 'uuid_generate' 的引用,即使我使用 -luuid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30273089/

相关文章:

ubuntu - 在 heroku 上安装 uuid-dev

Hibernate/JPA 2/PostgreSQL - 实体 UUID 作为主键

serialization - 如何序列化 boost::uuids::uuid

c++ - 为什么 A/<constant-int> 在 A 无符号与有符号时更快?

python - 如何生成uuid字符串

c++ - 如何在Qt中使用翻译?

c++ - 为什么 C++ 不允许将 void 参数传递给具有零参数的函数?

sql - 在 Postgres 中生成 UUID

c++ - 如何在 JetBrains Clion 中更改项目字符集

c++ - LabView 中的原生 Vector<Double> 作为参数/返回