This site is a part of Przemoc's network. Look also at my techblog.
 

gcc tips

General

Default defines

$ echo | gcc -E -dM -

MinGW

__declspec(dllexport), __stdcall and lacking underscore

Start with following article: Stdcall and DLL tools of MSVC and MinGW. You can read there that in MSVC DLL functions in stdcall calling convention and marked as __declspec(dllexport) are decorated with leading underscore and closing @nn, where nn is the number of bytes in the argument list. However, in MinGW DLL you won't find the underscore and this is a problem for MSVC applications loading DLLs and expecting such functions. The solution is to add aliases to .def's EXPORTS section with leading underscores. Makefile entry with sed doing the trick:

$(DLL): $(OBJS)
	dlltool -z $(@:.dll=.def) $(OBJS)
	del $(@:.dll=.def).bak 2>nul
	sed -ri.bak "/^EXPORTS/,/^[^ \t]/s/^([ \t]+)([^ \t]+).*/\1\2\n\1_\2 = \2/" $(@:.dll=.def)
	$(CXX) -shared -o $@ $(@:.dll=.def) $(OBJS)
 
tips/gcc.txt · Last modified: 2009.10.04 18:31 by przemoc
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki