转自:http://hi.baidu.com/oofy/blog/item/fa788a23ebdb4947ad34dede.html
一直没搞明白过这两个东西,今天花工夫用了一下.

总结如下:

mingw中创建dll有两种方式,一是使用    gcc -shared ...
二是使用dllwrap ...

dllwrap是一组工具的调用.gcc -shared是直接生成.

dllwrap相对更灵活一些.不过gcc -shared基本上也够用.

dlltool是用于生成def,exp,lib文件的工具.
它可以基于obj文件(基中函数标记为__declspec(dllexport))或def文件生成exp和lib文件.
前者(exp文件,其中包含了.edata段)是用于创建dll,后者(lib文件,包含.idata段)用于使用dll

dlltool中DLLNAME参数其实只用于产生def文件中library语名和lib中的dll名.
它本身并不需要dll的信息.

几个主要的参考文档:
使用gcc -shared创建dll,也是一个实验的好基础:
http://www.adp-gmbh.ch/win/misc/mingw/dll.html

gnu-binutils manual, as/ar/ranlib/dlltool/ld都是它的一部分
gcc -shared相关的几个参数:
--add-stdcall-alias                  Export symbols with and without @nn
--kill-at    Remove @nn from exported symbols
--out-implib <file>        Generate import library
--output-def <file>               Generate a .DEF file for the built DLL

dlltool的参数
-z --output-def <deffile> Name of .def file to be created.
--export-all-symbols Export all symbols to .def
--no-export-all-symbols Only export listed symbols
--exclude-symbols <list> Don't export <list>
--no-default-excludes Clear default exclude symbols
-b --base-file <basefile> Read linker generated base file.
-x --no-idata4 Don't generate idata$4 section.
-c --no-idata5 Don't generate idata$5 section.
-U --add-underscore Add underscores to symbols in interface library.
-k --kill-at Kill @<n> from exported names.
-A --add-stdcall-alias Add aliases without @<n>.
-p --ext-prefix-alias <prefix> Add aliases with <prefix>.

关于msvc和gcc中生成__stdcall调用的dll
http://www.geocities.com/yongweiwu/stdcall.htm

还有,就是亲手实验.