Reputation: 21
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?
Upvotes: 1
Views: 290
Reputation: 2424
I read GWAN's documentation. If you write your own library, you should be able to integrate well with it (treating it as a preexisting library).
myuuid.h
myuuid.c
Then generate your library, by compiling myuuid.c:
libmyuuid.a
Put the library as gwan/libraries/libuuid.a and try it as below.
#include "myuuid.h"
#pragma link "./libraries/myuuid"
int main(int argc, char *argv[])
{
my_uuid_generate();
return 0;
}
You may want to keep an eye on gwan/logs/gwan.log file to see if the link worked. You could also start GWAN server in a terminal, manually, to look at the errors.
Upvotes: 1
Reputation: 21
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)
Upvotes: 0
Reputation: 3334
The servlet
works because you are linking your script directly to an existing library (already compiled code).
The init.c
script fails to link because the "#pragma link "libraries/my_uuid.c"
library that calls a compiled library does not exist yet (it's still source code).
You should rather use #include "libraries/my_uuid.c"
in init.c
to have this kind of constructions work.
Upvotes: 0