Dynamic library



Hi all,

I've been trying get an example of loading a .so but it doesn't work.
Here's the lib:

#include "stdio.h"

void testme(void)
{
printf("Hello From Lib!");
}

And this is compiled as:
gcc -fPIC -shared file.c -o libmystuff.so

Then here's the file which tries to load it:
#include "stdio.h"
#include "dlfcn.h"

int main()
{
printf("Going to call library code\n");

void* handle = dlopen("/home/gamehack/shared/libmystuff.so)",
RTLD_LAZY);

if(!handle)
{
printf("not able to load\n");
char* errstr = dlerror();

if(errstr != NULL)
{
printf("%s\n", errstr);
}

return 1;
}

typedef void (*hello_t)();

hello_t hello = (hello_t) dlsym(handle, "testme");

if(!hello)
{
printf("Error!");
dlclose(handle);
}

hello();

printf("Closing the lib\n");
dlclose(handle);

return 0;
}

But it always fails:
gamehack@loopy:~/shared$ ./main
Going to call library code
not able to load
/home/gamehack/shared/libmystuff.so): cannot open shared object file:
No such file or directory

But gamehack@loopy:~/shared$ ls -al /home/gamehack/shared/ gives:
-rw-r--r-- 1 gamehack gamehack 948 2006-01-26 17:14 libmystuff.so

Any pointers why this is happening?

.



Relevant Pages

  • Re: [opensuse] How to set up LIRC?
    ... and if not then loading it and setting it to load at boot time. ... I Googled around and learned a bit about loading kernel modules but nothing answered this question. ... Well further Google attempts and a visit to the LIRC website seemed to indicate that I need another module loaded in the kernel called lirc_serial. ...
    (SuSE)
  • Re: Next Version of GDI+ (maybe GDI+ 2.0)
    ... loading and manipulating of such files isn't lightning fast unless you have really powerfull dedicated hardware. ... to see whole image you need to read whole image, and then eventualy generate a smaller sample for display. ... BUT to have this smaler sample you need to load ALL the pixels of oryginal image. ...
    (microsoft.public.dotnet.framework.drawing)
  • RE: 66 running processes?
    ... Win XP, a firewall and an AV and about seven background utilities, and with ... want it to load right from boot up, or could you take it off the load list ... Stopping programs you use loading early is only likely to make much ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Next Version of GDI+ (maybe GDI+ 2.0)
    ... Alejandro Lapeyre ... > loading and manipulating of such files isn't lightning fast unless you ... > smaller sample for display. ... > load ALL the pixels of oryginal image. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Filter on a forms recordsource
    ... What I'm trying to do is to load a record with its sub details in a subform. ... without loading the whole records and details of the database. ...
    (microsoft.public.access.queries)