|
From: Brian D. <br...@de...> - 2005-10-30 13:57:07
|
Stefan Bellon wrote: > Yes, I pretty much understand all of that. But in your example you > assume the DLL "foo.dll" to exist. My question is: How do I _create_ There are three scenarios that I can think of. A) The .exe links directly against the .dll, and the .dll uses GetProcAddress to access the symbols in the .exe. From the standpoint of the linker this is bog standard - creating the .dll does not depend on the .exe at all. gcc -shared foo.o -o foo.dll -Wl,--out-implib,libfoo.dll.a gcc main.o -o main.exe -lfoo B) The .exe uses LoadLibrary and GetProcAddress to load and access the .dll (such as in the case of a plugin that can be dynamically added/removed as necessary) and the .dll links directly against the .exe without using GetProcAddress. This is just the converse of the above, except that now creating the .exe does not depend on the .dll existing at all. gcc main.o -o main.exe -Wl,--out-implib,libmain.a gcc -shared foo.o -o foo.dll -lmain C) Both the .exe and the .dll link directly against each other; neither uses GetProcAddress. Here there is a circular dependency that you have to break by creating a .def file by hand and then using dlltool to turn that into an import library. You can create the .def file for either the .exe or the .dll - it really just depends on which has the more complex set of exports, and how your build is structured. Let's assume for the example you choose to write the .exe's .def file by hand, but you can just as well do it the opposite way. # create main.def dlltool --input-def main.def --output-lib libmain.a --dllname main.exe gcc -shared foo.o -o foo.dll -lmain -Wl,--out-implib,libfoo.dll.a gcc main.o -o main.exe -lfoo Note that in B) and C) you hardcode the name of the .exe into the .dll, so it can only ever be used with that .exe and not as a general purpose library. In all three cases you need __declspec(dllexport) on the symbols in main. Brian |