Web lists-archives.org

Re: [Mingw-users] Help exporting functions from an exe




> That makes no sense.  An exe file does not export functions or variables..

Not very often, true, but an exe file can have an export table just
like DLLs typically have. I will show you. Create these three files:

main.c:
== cut here ==
#include <stdio.h>

__declspec(dllexport) void
foo(void)
{
  printf ("Goodbye world\n");
}

__declspec(dllimport) void bar(void);

int
main (int argc, char **argv)
{
  bar ();
  return 0;
}
== cut here ==

dll.c:
== cut here ==
#include <stdio.h>

__declspec(dllimport) void foo(void);

__declspec(dllexport) void
bar(void)
{
  printf ("Hello world\n");
  foo ();
}
== cut here ==

And main.def:
== cut here ==
EXPORTS
foo
== cut here ==

Then run:

dlltool -D main.exe -d main.def -l libmain.dll.a
gcc -Wall -shared -o dll.dll -Wl,--out-implib,libdll.dll.a l.c -L. -lmain
gcc -Wall -o main.exe in.c -L. -ldll

And then verify with objdump -p that indeed main.exe exports foo and
imports bar from dll.dll, and dll.dll exports bar and imports foo from
main.exe.

Instead of a DLL explicitly "statically" importing a function (or
variable) from a named exe as in this example, what is much more
common is that some library dynamically looks up the name of a
function exported from the main exe, which typically happens in
environments where some degree of interpretation is going on.

--tml

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users