Search code examples
g-wan

Linking another library from C-library in gwan/libraries results in "undefined symbol" error


I'm trying to use a standard library libuuid inside my C-library file my_uuid.c:

gwan/libraries/my_uuid.c:

#include <uuid/uuid.h>
#pragma link "uuid"
void my_uuid_generate(uuid_t uuid)
{
  uuid_generate(uuid);
}

gwan/init.c:

#include <uuid/uuid.h>
#pragma link "uuid"
#pragma link "libraries/my_uuid.c"
int main(int argc, char *argv[])
{
  uuid_t uuid;
  my_uuid_generate(uuid);
  return 0;
}

However, G-Wan fails to start and prints such message:

Linking ./init.c: undefined symbol: uuid_generate

This mustn't be the problem of libuuid installation or non-standard path, because such servlet does work successfully:

#include <uuid/uuid.h>
#pragma link "uuid"
int main(int argc, char *argv[])
{
   uuid_t uuid;
   char str[256];

   uuid_generate(uuid);
   uuid_unparse(uuid, str);
   printf("%s\n", str);

   xbuf_cat(get_reply(argv), "Hello, World!");
   return 200;
}

The problem might be due to that G-Wan first loads init.c and then my_uuid.c instead of libuuid, even though I have #pragma link "uuid" in init.c.

Does anybody know how to solve the problem? Is it considered valid to link other libraries from C-file libraries in gwan/libraries?


Solution

  • Interestingly, G-Wan successfully started when I moved #pragma link "uuid" below the #pragma link "libraries/my_uuid.c" in init.c file:

    #include <uuid/uuid.h>
    #pragma link "libraries/my_uuid.c"
    #pragma link "uuid"
    int main(int argc, char *argv[])
    {
      uuid_t uuid;
      my_uuid_generate(uuid);
      return 0;
    }
    

    Definitely, it changed the order in which G-Wan loads libuuid and my_uuid.c. Now it first loads libuuid (with uuid_generate() symbol) and then my_uuid.c (with my_uuid_generate() symbol, which in turn calls uuid_generate()).

    Gil, do I correctly understand that currently G-Wan is not designed to provide a controllable order of library loads? Can the G-Wan team consider updating the G-Wan server to load the libraries in a controllable/predicatable order, at least in some extent? I.e. load the dependencies before the dependency users. For example we should be able to write such code as below and the G-Wan server to load first libuuid, then my_uuid.c, then init.c:

    gwan/libraries/my_uuid.c:

    #pragma link "uuid"
    

    gwan/init.c:

    #pragma link "libraries/my_uuid.c"
    

    (notice no #pragma link "uuid" in init.c)