Linking wine * libraries with Linux applications ?!

Troy Rollo wine at
Thu Oct 20 15:49:18 CDT 2005

On Thursday 20 October 2005 22:45, Alexander Efremov wrote:
> The
> architecture is somethink like
> |Linux Executable| --uses--> |Linux *.a and *.so libraries| +
> + |my Linux *.so library| --uses--> |Other Linux *.a and *.so
> libraries + WineLib|

OK, then you will need to use the longjmp method.

> By the way what exactly causes the segmentation fault during the
> execution ?

Something (and it could be one of many things) that is not initialised when 
you call the library.
> A also tried to compile and link WineLib * applications using
> normal g++ for compilation and linking - just ignoring all the
> resource files - and it worked... but at the end i got the same
> segmantation fault :-(

That is what I would expect. You can't just use normal g++ - winegcc is doing 
a lot of magic stuff for Wine.

It looks like you are going to have to use the longjmp method. Create a 
WineLib application whose WinMain just jumps back to some other routine. It 
will probably be worth patching winegcc and the Wine launcher code so that 
winegcc marks the executable at 3Gig-aware (based on a flag to winegcc) and 
the Wine launcher code recognises the flag and avoids reserving the 2-3G part 
of the address space. This should be enough that you can avoid mucking about 
with stacks and unmapping stuff wine has mapped.

You should have an arrangement that looks something like this:

	1. Your DLL that wants to call the Win32 API links to a ""
	    with an entry point "start_wine_lib_for_dll".

	2. "" is a winelib app. "start_wine_lib_for_dll" would contain
	    a "setjmp" followed by a call to wine_init, passing a dummied up argv
	    that tells wine to start "".

	3. WinMain in "" does a longjmp back to

	4. From this point on you should be able to call the Win32 API as much as
	    you like, even from files compiled with plain old gcc or g++.

	5. You may need to set up an exception frame that does something like
	    calling "exit" after printing a message about there being an
	    unhandled exception.

More information about the wine-devel mailing list