2002-10-12 09:52:15 +04:00
|
|
|
#include <stdio.h>
|
2002-10-16 05:28:41 +04:00
|
|
|
#define LT_SCOPE extern /* so that ltdl.h does not export anything */
|
2002-10-12 09:52:15 +04:00
|
|
|
#include <ltdl.h>
|
|
|
|
#define MAIN_DLL_EXPORT
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
const char *version_string = "uselib-test6-1.0";
|
|
|
|
|
|
|
|
int register_module (const char *name)
|
|
|
|
{
|
|
|
|
printf ("register_module was called by module '%s'\n", name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module (const char *fmt, const char *name)
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
sprintf (buf, fmt, name);
|
2002-10-13 06:26:09 +04:00
|
|
|
printf ("loading module from %s\n", buf);
|
2002-10-16 05:28:41 +04:00
|
|
|
lt_dlhandle handle = lt_dlopenext (buf);
|
2002-10-16 08:07:58 +04:00
|
|
|
printf ("handle is VARIES{%p}\n", handle);
|
2002-10-12 09:52:15 +04:00
|
|
|
if (!handle) {
|
|
|
|
printf ("lt_dlopen error: %s\n", lt_dlerror ());
|
2002-10-12 15:50:28 +04:00
|
|
|
return -1;
|
2002-10-12 09:52:15 +04:00
|
|
|
}
|
2002-10-12 15:50:28 +04:00
|
|
|
modload_func func = (modload_func) lt_dlsym (handle, "module_init");
|
2002-10-16 08:07:58 +04:00
|
|
|
printf ("module_init function is at VARIES{%p}\n", func);
|
2002-10-12 09:52:15 +04:00
|
|
|
if (func != NULL) {
|
|
|
|
printf ("Calling module_init\n");
|
|
|
|
(*func)();
|
|
|
|
} else {
|
2002-10-12 15:50:28 +04:00
|
|
|
printf ("lt_dlsym error: %s\n", lt_dlerror ());
|
|
|
|
return -1;
|
2002-10-12 09:52:15 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
printf ("start\n");
|
2002-10-13 06:28:06 +04:00
|
|
|
if (lt_dlinit () != 0) {
|
|
|
|
printf ("lt_dlinit error: %s\n", lt_dlerror ());
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-16 05:28:41 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
const char *module_name_format = "%s";
|
|
|
|
#else
|
|
|
|
const char *module_name_format = "lib%s.la";
|
|
|
|
#endif
|
2002-10-12 09:52:15 +04:00
|
|
|
printf ("loading module1\n");
|
|
|
|
// try to load module1
|
2002-10-16 05:28:41 +04:00
|
|
|
if (load_module (module_name_format, "module1") < 0) {
|
2002-10-12 09:52:15 +04:00
|
|
|
printf ("load module1 failed\n");
|
|
|
|
}
|
2002-10-16 05:28:41 +04:00
|
|
|
if (load_module (module_name_format, "module2") < 0) {
|
2002-10-12 09:52:15 +04:00
|
|
|
printf ("load module2 failed\n");
|
|
|
|
}
|
2002-10-13 06:26:09 +04:00
|
|
|
int arg;
|
|
|
|
for (int arg=1; arg < argc; arg++) {
|
2002-10-16 05:28:41 +04:00
|
|
|
if (load_module (module_name_format, argv[arg]) < 0) {
|
2002-10-13 06:26:09 +04:00
|
|
|
printf ("load %s failed\n", argv[arg]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-12 09:52:15 +04:00
|
|
|
printf ("stop\n");
|
2002-10-16 08:07:58 +04:00
|
|
|
exit (77);
|
2002-10-12 09:52:15 +04:00
|
|
|
}
|