Subject: Re: _beginthread Problems with win95 and mingw32 using C++
From: [email-masked] (Fergus Henderson)

7 Dec 1997 01:32:52 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
To: [email-masked]
Cc: [email-masked]

John Miller <[email-masked]> writes:

>Colin Peters wrote:
>
>> The reason the function doesn't work without __cdecl__ is that it is
>> getting name mangled like a C++ function (I think, see below). The header
>> file should feature a pair of sequences like this around the _beginthread
>> and other prototypes:
>>
>> #ifdef __cplusplus
>> extern "C" {
>> #endif
>>
>> ... function prototypes ...
>>
>> #ifdef __cplusplus
>> }
>> #endif
>
>This is indeed included in the header file.

Hmm...

>> The version of Mingw32 you are using might have a bug in that header. You
>> could try downloading version 0.1.4 from my web page, or the latest
>> snapshot if you feel brave (on second thought, if you download the latest
>> snapshot only pull out the process.h header file, the new specs won't work
>> with b18).
>
>> Now that it occurs to me, what does that prototype look like? It should be
>>
>> unsigned long _beginthread (void (*pfuncStart)(void *), unsigned
>> unStackSize, void* pArgList);
>>
>> It occurs to me that older versions of Mingw32 might have had an attempt
>> to cdecl pfuncStart, which is unnecessary and may cause problems in some
>> cases. Grab process.h out of 0.1.4 (I think) or the latest snapshot. Or
>> just replace the prototype with the one given above.
>
>Did so and this did indeed fix the problem (Yes!)  but...
>
>Now I can compile an object file correctly but I now am not able to link
>correctly to _beginthread.  ld returns error :
>
>test.o(.text+0x3d):test.cc: undefined reference to `_beginthread(void (*)(void
>*), unsigned int, void *)'

The linker error message includes the function argument types,
which indicates that the name has been mangled (the linker is
nice enough to demangle it when printing the error).

Are you *sure* the header file has an `extern "C" { ... }'
around the declaration of _beginthread()?

You could try replacing the prototype with one that
explicitly includes `extern "C"', e.g.

	extern "C" unsigned long _beginthread (void (*pfuncStart)(void *),
				unsigned unStackSize, void* pArgList);

--
Fergus Henderson <[email-masked]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [email-masked]         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".