gmodule help
- From: "Greg Steffensen" <greg steffensen gmail com>
- To: gtk-list gnome org
- Subject: gmodule help
- Date: Fri, 7 Apr 2006 14:08:59 -0400
Hey, I'm trying to use gmodule, but am unfamiliar with libtool and linking, and am unsure about what compilation commands to use (I've gone through the libtool info pages, but still can't quite get it to work). Can anyone tell me how to compile a single source file that uses glib and gmodule into a ".so" file on Linux, such that gmodule can use it? I've pasted the source for the very simple test library and test executable I'm trying to get to work below, though I don't expect that their contents are important. Many thanks,
Greg
testplugin.c (to be compiled into a dynamically loadable library)
--------------------------
#include <glib.h>
#include <gmodule.h>
G_MODULE_EXPORT int test_func(gboolean bar) {
return bar ? 1 : 2;
}
test.c (an executable that loads the library at runtime)
------------------------
#include <glib.h>
#include <gmodule.h>
#define PLUGIN_FILE "./libtestplugin.so"
typedef int (* TestFunc) (gboolean);
int main() {
GModule *mod;
TestFunc module_func;
// open the module
g_assert(g_module_supported());
g_assert((mod = g_module_open(PLUGIN_FILE, G_MODULE_BIND_LAZY)) != NULL);
// get a pointer a function
g_assert(g_module_symbol(mod, "test_func", (gpointer)module_func));
// test a module function
g_print("%i\n", module_func(TRUE));
g_print("%i\n", module_func(FALSE));
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]