|
From: Tor L. <tm...@ik...> - 2005-10-29 23:47:47
|
> 2) On GNU/Linux, I have one project where one shared object refers
> back to symbols of the main application. [...] Now, when trying to
> build the same on Windows (using gcc -shared as well), the DLL
> doesn't even build but throws errors of "undefined references". I
> want those to get resolved when linking against the main
> application. Is such a set-up not possible on Windows?
It is possible, but it is not as flexible as on ELF-based systems like
Linux. Firstly, you must mark the function in the main .exe that you
want to access from a DLL for export using
__declspec(dllexport). Then, there are two possibilities how to
actually access the functions from the DLL:
1) you can create an import library for the foo.exe using a foo.def
file like this:
EXPORTS
some_function_in_main
and dlltool:
dlltool --input-def foo.def --output-lib libfoo.a --dllname foo.exe
Then link the DLL with libfoo.a.
This has the disadvantage that the .exe really has to be called
*exactly* foo.exe. This might be a disadvantage.
2) Look up the symbol at runtime. Read up on GetProcAddress() and
GetModuleHandle().
--tml
|