Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to 'uuid_generate' even though I use -luuid [duplicate]

Tags:

c++

uuid

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;
}

I am using Ubuntu 14

I am running my test.cpp as ...

g++ -luuid test.cpp

and the output

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

My g++ version:

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

and I already have uuid-dev installed.

sudo apt-get install uuid uuid-dev

uuid is already the newest version.
uuid-dev is already the newest version.
like image 723
SuVeRa Avatar asked May 16 '15 07:05

SuVeRa


1 Answers

Order of linked libraries matters, you need to add the -luuid after the module it's referenced from:

g++ test.cpp -luuid

unless you are using the grouping options (-Wl,--start-group,-Wl,--end-group).

See also this answer for more detail.

like image 63
πάντα ῥεῖ Avatar answered Oct 09 '22 01:10

πάντα ῥεῖ