Thread: undefined reference to `uuid_generate'

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    22

    undefined reference to `uuid_generate'

    Hi, I tried to construct a simple program to generate an uuid.
    Code:
    #include <stdio.h>
    #include <uuid/uuid.h>
    int main()
    {
      get_uuid();
      return 1;
    }
    
    int get_uuid()
    {
      uuid_t uuid;
      uuid_generate(uuid);
      return 1;
    }
    But it gives the following compilation error.

    lsf@lsf-laptop:~/mesh_project/cexample$ gcc -o uuid_test uuid_test.c
    /tmp/ccCgFyZU.o: In function `get_uuid':
    uuid_test.c.text+0x3c): undefined reference to `uuid_generate'
    collect2: ld returned 1 exit status

    what goes wrong with my code? appreciate you every advice.
    nuwan

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You forgot to link in the uuid library. Add -luuid to the end of your build command.

    Simply including a header (except for standard C functions, and then not necessarily for math functions) generally isn't sufficient to get the functionality it describes. C doesn't specify a mechanism for tying headers to libraries, so you have to know to both #include the proper headers and link in the proper libraries.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    22
    thanks a lot. I am new to C. it works now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM