This is, IMHO, a flaw in Winelib.
The problem is that Winelib is not fully initialized
until after PROCESS_InitWineLib(...) is called.
PROCESS_InitWineLib should be called out of
your apps main(), which is usually in the generated
.spec.c file.
As ld.so loads your app, it loads dependent .so libraries.
Part of the load process is to invoke all constructors
inside each .so. After all libraries are loaded,
and all constructors called, then main() is called.
Thus, when your constructors call CreateMutex,
they try to contact the server. They can't contact
the server, because it hasn't been started yet.
FYI, this is the same behavior you get with an MFC
application right now.
There are several ways around this. First, you can
modify your constructors to invoke PROCESS_InitWineLib(...)
prior to making any other calls. This can be a bit tricky
and hackish, because AFAIK, there is no easy way to
indicate to ld.so that a particular constructor must go
first. As a first pass hack, if you put the .o file
with the PROCESS_InitWineLib call on the link line first,
it will generally get invoked first.
The *right* solution is to modify Winelib so that
after all Winelib constructors are run, the library
is up and fully operational.
I have a kludge^H^H^H^H^H^Hpatch that starts this implementation
(so that I can support MFC the 'right' way), but to be honest,
it is buggy, and I haven't had the time to shake out the problems
with it (at first glance, it's pretty straight forward; someone could
probably recreate what I've got and go on to finish it 'right' pretty
quickly).
However, there is another way around this, that would be very
quick and dirty, and might be better for you, at least until
we get Winelib straightened out.
If you convert your app to be a small loader stub, and move all
of what had been your mainline app into a separate dll (or .so),
you can let your app come up, since there are no constructors it
will go through and initialize correctly. Then, you can call
LoadLibrary() or dl_open your your .so file, and using
GetProcAddress or dl_sym find 'WinMain' and invoke WinMain.
Thus, you defer the invocation of your constructors until
after Winelib is up and fully initialized.
I hope this helps; sorry for the long answer, just happen
to be hip deep in this one right now.
Jeremy
Ravichandra VN x7-6514 wrote:
>
> Hi,
>
> I have tried to port Win32 apps on to RH linux.
>
> It dumped core during creation of constructers. It does not reach main.
>
> libwine is the first one to be loaded while execution. And when one
> call to new Mutex (one of internal class) would in turn call
> CreateMutexW with (Null, FALSE,
> Null) which in turn calls get_req_buffer which returns NULL instead
> of returning buffer. any idea where
> I am going wrong.
>
> Thanks for your time.
>
> Rav