This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

exporting symbols from executable and linking shared objects question



Hi!!

I'm new to the list, but I searched archives looking for a solution and
found nothing.

I have TWO questions, but it's the same problem.

First is -rdynamic swich for gcc. it's used to export symbols for shared
objects and the second is about linking shared objects (.dll) with symbols
declared as external.

Let's see following code:

---main.c---
#include <dlfcn.h>
#include <stdio.h>

int c;

main () {

        int (*foo)();
        void *handler = dlopen ("./foo.so", RTLD_LAZY|RTLD_GLOBAL);
        if (!handler) {
                fputs (dlerror(), stderr);
                printf("\n");
                exit(1);
        }
        foo = dlsym(handler,"foo");

        (*foo)();
        dlclose(handler);
}
---main.c---

and following shared object source:

---foo.c---
//extern int c;

foo () {
        printf("Fooo!\n");
//        printf("c=%i\n",c);
}
---foo.c---

If I compile it under Unix or windows (under Win using attached shell
script -- refering to the documentation) everything is OK. But WHAT I have
to do to get it working with foo looking like this:

---foo.c---
extern int c;

foo () {
        printf("Fooo!\n");
        printf("c=%i\n",c);
}
---foo.c---     


Under Unix I used to compile main:
gcc main.c -o main -ldl -rdynamic
(to export symbols to dynamically dlopened shared objects), and foo:
gcc -shared foo.c -o foo.so

First of all -rdynamic does not work under cygwin and moreover ld fails
linking shared objects with symbols declared as external.

Any suggestions???

Regards,

--
Mariusz Wołoszyn
Internet Security Specialist, Internet Partners

ll.sh

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]