From: Codeplug <gra...@ch...> - 2009-02-26 16:55:17
|
chris wrote: > Hello, > > I'm using the following command to build a .dll without the C runtime > dependency (or any dependency for that matter): > > g++ -Wl,--subsystem,console -nodefaultlibs -nostartfiles -shared -s -o > mydll.dll main.o > > However, the following warning is issued: > > ld.exe: warning: cannot find entry symbol _DllMainCRTStartup@12; > defaulting to 10001000 > > In main.cpp, this exists: > > extern "C" BOOL WINAPI _DllMainCRTStartup(HINSTANCE hinstDLL, DWORD > fdwReason, LPVOID lpvReserved) { return TRUE; } > "WINAPI" typically resolves to __stdcall. Both MSVC and MinGW will decorate the names with a leading underscore and trailing @N. (NOTE: MinGW will omit the leading underscore for __stdcall when exporting from a dll - for some reason - which doesn't really apply here.) > This works under MSVC. > > To make this work in MinGW, I have to declare the function like such: > > extern "C" BOOL WINAPI DllMainCRTStartup(HINSTANCE hinstDLL, DWORD > fdwReason, LPVOID lpvReserved) { return TRUE; } > > (ie without the prefix underscore) > > It is not desirable to have to change the .cpp code depending if it is > built for MinGW or MSVC. > > Do note, that MSVC gives this error if the that function does not exist > as it is supposed to be named: > > LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12 > > Can anyone shed some light onto this discrepancy between MSVC and MinGW > and available solutions or workarounds at the tool level? > > Thanks. > > chris The MS-CRT declares: "BOOL WINAPI _DllMainCRTStartup" (which "C" linkage), which yields a decorated name of "__DllMainCRTStartup@12". However, the default entry point for MinGW seems to be "_DllMainCRTStartup@12" - thus your issue. What I would do is just use "DllMain", then use command line options to specify the entry point to use. Here's what I used to link C++ code without a CRT under MinGW: compile: "-fno-exceptions -fno-rtti" link: "-mdll -entry=_DllMain@12 -lkernel32 -nostdlib" Are you sure you want to run with no CRT under C++? You won't have global constructors/destructors (link error if you have any) and no exceptions and no RTTI... gg |