Winelib and C++ static initialization

Stefan Dösinger stefandoesinger at gmail.com
Wed Aug 26 10:35:52 CDT 2015


-----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 at retina ~/Desktop $ ~/build/wine/tools/winegcc/wineg++ test.cpp -o test.exe.so
stefan at retina ~/Desktop $ ~/build/wine/wine test.exe.so 
Init ctor
Segmentation fault
stefan at retina ~/Desktop $ 

A binary compiled with mingw works OK:

stefan at retina ~/Desktop $ i686-w64-mingw32-c++ test.cpp -o test.exe -static
stefan at retina ~/Desktop $ ~/build/wine/wine test.exe    
Init ctor
WinMain()
stefan at 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.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJV3dzYAAoJEN0/YqbEcdMwuUoP/2WCjtXJNTJbF8IEMoVCqXbe
JhiedCfjbPagAdO+KkN9NHzLsGu9aEUgTFPzPXXSSRZQF8mASkujz5GQtqz0+4k7
dCoEocSVkqoZwmIB39jjueQV7hyz5wYNEXY5JDCBadbwjEcQqONs5OIHmr8P5Scx
OrWmsx8p2hP4rfl5fIjKmCvjsuUA+V12JP8sPD3DLxZG2KFQLCtD2SvcXgmB3jOZ
mjD0170nQqEoyipeIamqndSCvBfZUE47kCFBRWYMrq2+ofFxaxRRQwuei/gTw9P/
P2EK+aCz8BzIJipFm7SJKhOhrGV5g7yr554NltSpAlmrLtRUtmyKCGemj7QrewJw
/U4EEl9SI3h85SR8VrkeJ0oS21TVTx7PXGupyIJdl9OUKpx6x8EIayzzOwnLOmbw
jna+cvwOipoLiNNDC6NimAeoEXRC7W7QmkBpq6FDXz/6RBUd8oxGwd6mZXfL6PNg
/mIzxIg0fByiCRw7IncxT0HV7mtHoXCzMlJwpOFKLzXmbe8x6THD/7sPNwVxgtwO
/zQ6P+Ig1pq38Kg+88rc96YowNxVhQdH0Ko1KbzwIqKPr/42l6KJbj6B75TEnxJB
6krDPMdGZq2sYRV+NVLfRir3GutZ+60WocZdz7zuGlnfrKIEFYg+MO+9G4uts22K
7f7LuaoKhnhlOaZoR0PD
=VRIZ
-----END PGP SIGNATURE-----



More information about the wine-devel mailing list