help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need help to build shared object


From: Jose Manuel Lorenzo Lopez
Subject: Need help to build shared object
Date: Wed, 28 Nov 2001 22:19:54 +0100

Hello community,

I have big troubles building and using a shared object using the dl-interface 
with g++ and don't know how to go on. May be it is a common error as I am 
misunderstanding anything. :( Let me tell you what the problem is:

Using for example the following tiny code, that will be the shared object to 
call:


##### file test_shared.cpp ######
#include <iostream.h>
 
int hallo() {
        cout<<"Yeah Great!\n";
        return 0;
}


I compiled this  in the following manner:

g++ -fPIC -Wall -g -c test_shared.cpp
g++ -g -shared -WL,-soname,test_shared.so.1 -o test_shared.so.1.0 
test_shared.o 
ln -sf test_shared.so.1.0 test_shared.so.1

This works well!!!

Then I created this little program to call the shared object:

##### file main.cpp #####
#include <stdio.h>
#include <dlfcn.h>
 
int (*hello)();
 
int main() {
 
        void *library;
        void *hello;
        const char *error;
 
        library = dlopen("/home/jose/test_shared/test_shared.so.1",RTLD_NOW);
        if (library == NULL) {
                fprintf(stderr,"Can not find the library: %s\n",dlerror());
                return 1;
        }
 
        hello = dlsym(library, "hallo");
        error = dlerror();
 
        if (error != NULL) {
                fprintf(stderr,"Can not find hallo: %s\n",error);
                return 2;
        }

 
        (*hello)();
        dlclose(library);
        return 0;
}

Okay, that's it! Now it's time to merge altogether to get the app! :)
So I do the following:

g++ -o test_shared main.cpp -ldl
main.cpp: In function `int main()':
main.cpp:26: void value not ignored as it ought to be

What the hell is the compiler trying to tell me????? :)
I am trying this with g++ 2.95.3 on i386 arch with SuSE Linux 7.2

May anyone is able to enlight me a bit!
Thanks in advance for your help!

Best Regards / Un saludo / Mit freundlichen Grüßen

Jose Manuel Lorenzo Lopez



reply via email to

[Prev in Thread] Current Thread [Next in Thread]