即使我使用了-luuid,仍然出现“undefined reference to 'uuid_generate'”的错误提示。

8

My test.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.

1
你尝试过 g++ test.cpp -luuid 吗? - πάντα ῥεῖ
哇,它成功了!你能否添加一些解释作为答案?我会接受它。 - SuVeRa
1个回答

7

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

g++ test.cpp -luuid

除非您正在使用分组选项 (-Wl,--start-group,-Wl,--end-group),否则不建议这样做。

更多详情请参见此答案


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接