Dynamic library
- From: gamehack@xxxxxxxxx
- Date: 26 Jan 2006 10:16:07 -0800
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?
.
- Follow-Ups:
- Re: Dynamic library
- From: Bill Marcum
- Re: Dynamic library
- From: Måns Rullgård
- Re: Dynamic library
- From: "Nils O. Selåsdal"
- Re: Dynamic library
- Prev by Date: Re: Tool to compress a bunch of install files on Linux
- Next by Date: Re: Dynamic library
- Previous by thread: Re: Tool to compress a bunch of install files on Linux
- Next by thread: Re: Dynamic library
- Index(es):
Relevant Pages
|