This is the mail archive of the cygwin@sources.redhat.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]

Solution: Exporting symbols from an executable


Greetings,

The Solution - to export symbols from an executable (example is below):

$ dlltool --dllname a.exe --def a.def --output-lib liba.a --output-exp a.exp
$ gcc -o a.exe a.exp a.c
$ gcc --shared b.c -o b.dll liba.a
$ ./a.exe
Succeeded

Jason Tishler suggested that I try postgresql build to see what it
does.  It does a five step process to get things to work.  To be
honest this five step process is described elsewhere for building
dlls.  But since I could build dlls in one step (using -shared), I
figured all this was obsolete documentation.

The above two step (first two commands) subset works for me.

The main thing I was missing is that you HAVE to create a .exp file.
Since most other dlltool functionality is subsumed by ld, I wonder why
this isn't.  Or if there's some option that I couldn't figure out.

My biggest concern is that I skipped the base file creation (from the
five step process).  Things still seem to work.  Does it matter?

All the exports are purely functional (no data).

[Excerpts from my original post to the newsgroup to make this complete]

I want to export symbols from an executable, so that they can be used
to resolve symbols at run time from dlopen'ed libraries.

a.c : defines main and f1()
b.c : defines f2() which uses f1().

I want to end up with a.exe and b.dll.  So that when a.c dlopens b.dll,
f1 is resolved.

The files are :

---a.c----
#include <errno.h>
#include <dlfcn.h>

int f1(void)
{
    return 1;
}

main()
{
    void *p = dlopen(".\\b.dll", RTLD_NOW);
    if (p == 0)
    {
	printf("Failed\n");
	printf("%s\n", strerror(errno));
    }
    else 
    {
	printf("Succeeded\n");
    }
}
----b.c----
#include <cygwin/cygwin_dll.h>

extern int f1(void);

int f2 (void)
{
    return f1();
}

DECLARE_CYGWIN_DLL(DllMain);

----a.def----
EXPORTS
   f1
----------------

-- 
Regards
_______________________________________________________________________
Venkat Iyer       venkat@comit.com          Phone: 1-408-988-2988 x 136 
Comit Systems, Inc.   The Contract Engineering Company    www.comit.com


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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