This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?

(35个答案)


5年前关闭。




我的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.

最佳答案

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

g++ test.cpp -luuid

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

有关更多详细信息,另请参见this answer

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

10-11 22:51
查看更多