Hi,
I am new to Winelib and I have crashes with very basic C++ code. Consider the following code:
#include <windows.h>
struct MyInit { MyInit() { OutputDebugStringA("Init ctor\n"); } }; MyInit InitObj;
extern "C" int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { OutputDebugStringA("WinMain()\n"); return 0; }
If I compile it on Ubuntu 32-bit with wine-1.6.2 with:
wineg++ -c -mno-cygwin -o hello.o hello.cpp wineg++ -mwindows -mno-cygwin -o hellocpp.exe hello.o
The result is:
$ ./hellocpp.exe Segmentation fault (core dumped)
On Windows this program obviously outputs "Init ctor\n" followed by "WinMain()\n", as viewed in DbgView. Removing the call to OutputDebugStringA from the static constructor prevents the crash in Winelib.
How do I get C++ static initialization to work properly in Winelib?
Thanks, Luke
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Am 2015-08-26 um 16:33 schrieb Luke Dunstan:
If I compile it on Ubuntu 32-bit with wine-1.6.2 with:
Please upgrade to Wine 1.7 for anything development related.
#include <windows.h>
struct MyInit { MyInit() { OutputDebugStringA("Init ctor\n"); } }; MyInit InitObj;
extern "C" int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { OutputDebugStringA("WinMain()\n"); return 0; }
I found that OutputDebugStringA doesn't write anything here, even if successful. I replaced it with printf calls to get actual output.
$ ./hellocpp.exe Segmentation fault (core dumped)
Try running it with "wine hellocpp.exe".
Though it's not quite working here either:
stefan@retina ~/Desktop $ ~/build/wine/tools/winegcc/wineg++ test.cpp -o test.exe.so stefan@retina ~/Desktop $ ~/build/wine/wine test.exe.so Init ctor Segmentation fault stefan@retina ~/Desktop $
A binary compiled with mingw works OK:
stefan@retina ~/Desktop $ i686-w64-mingw32-c++ test.cpp -o test.exe -static stefan@retina ~/Desktop $ ~/build/wine/wine test.exe Init ctor WinMain() stefan@retina ~/Desktop $
Is there a particular reason why you need Winelib? Usually it's recommended to stick to whatever compiler you're using to create the Windows executable and just running that. The only reason when a winelib compile brings you something is when you want to target a CPU architecture that the Windows tools can't build for, e.g. PowerPC or MIPS.