Back to index

glibc  2.9
origtest.c
Go to the documentation of this file.
00001 #include <dlfcn.h>
00002 #include <error.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 
00006 int
00007 main (void)
00008 {
00009   void *h;
00010   int (*fp) (int);
00011   int res;
00012 
00013   h = dlopen ("${ORIGIN}/testobj1.so", RTLD_LAZY);
00014   if (h == NULL)
00015     error (EXIT_FAILURE, 0, "while loading `%s': %s", "testobj1.so",
00016           dlerror ());
00017 
00018   fp = dlsym (h, "obj1func1");
00019   if (fp == NULL)
00020     error (EXIT_FAILURE, 0, "getting `obj1func1' in `%s': %s",
00021           "testobj1.so", dlerror ());
00022 
00023   res = fp (10);
00024   printf ("fp(10) = %d\n", res);
00025 
00026   if (dlclose (h) != 0)
00027     error (EXIT_FAILURE, 0, "while close `%s': %s",
00028           "testobj1.so", dlerror ());
00029 
00030   return res != 42;
00031 }
00032 
00033 
00034 extern int foo (int a);
00035 int
00036 foo (int a)
00037 {
00038   return a + 10;
00039 }