By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,548 Members | 1,735 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,548 IT Pros & Developers. It's quick & easy.

How to use dlopen()???

P: n/a
Hi all...
I wrote a simple program to test the dlopen()...\

#include <dlfcn.h>

int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;

handle = dlopen ("plugins/test", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}

dlerror(); /* Clear any existing error */
....
I also made a libtest.so in the plugins/test dir.
But the compiler give me the message as follow.

inst.h:21: warning: useless keyword or type name in empty declaration
/tmp/cc2c6Rb1.o(.text+0x27): In function `main':
: undefined reference to `dlopen'
/tmp/cc2c6Rb1.o(.text+0x3e): In function `main':
: undefined reference to `dlerror'
/tmp/cc2c6Rb1.o(.text+0x64): In function `main':
: undefined reference to `dlerror'
/tmp/cc2c6Rb1.o(.text+0x6f): In function `main':
: undefined reference to `dlclose'
collect2: ld returned 1 exit status

what's happened????

Nov 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dave wrote:
Hi all...
I wrote a simple program to test the dlopen()...\

#include <dlfcn.h>

int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;

handle = dlopen ("plugins/test", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}

dlerror(); /* Clear any existing error */
...
I also made a libtest.so in the plugins/test dir.
But the compiler give me the message as follow.

inst.h:21: warning: useless keyword or type name in empty declaration
/tmp/cc2c6Rb1.o(.text+0x27): In function `main':
: undefined reference to `dlopen'
/tmp/cc2c6Rb1.o(.text+0x3e): In function `main':
: undefined reference to `dlerror'
/tmp/cc2c6Rb1.o(.text+0x64): In function `main':
: undefined reference to `dlerror'
/tmp/cc2c6Rb1.o(.text+0x6f): In function `main':
: undefined reference to `dlclose'
collect2: ld returned 1 exit status

what's happened????


comp.programmer.unix or gnu.gcc.help are better places for questions
about dynamic libraries if I read the tea leaves above right.
They are off topic here.

But for the generic question of why symbols can't be found, a generic
answer
of "you need to link against the library that exports them" fits OK
here I guess.

-David

Nov 14 '05 #2

P: n/a
> inst.h:21: warning: useless keyword or type name in empty declaration
/tmp/cc2c6Rb1.o(.text+0x27): In function `main':
: undefined reference to `dlopen'
/tmp/cc2c6Rb1.o(.text+0x3e): In function `main':
: undefined reference to `dlerror'
/tmp/cc2c6Rb1.o(.text+0x64): In function `main':
: undefined reference to `dlerror'
/tmp/cc2c6Rb1.o(.text+0x6f): In function `main':
: undefined reference to `dlclose'
collect2: ld returned 1 exit status


Offtopic, but I'd add a -ldl to your gcc command line.

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.