delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/12/07/01:32:52

From: fjh AT cs DOT mu DOT OZ DOT AU (Fergus Henderson)
Subject: Re: _beginthread Problems with win95 and mingw32 using C++
7 Dec 1997 01:32:52 -0800 :
Message-ID: <199712070909.UAA06549.cygnus.gnu-win32@mundook.cs.mu.OZ.AU>
References: <01bd0141$5f8510a0$fa173185 AT gbird0 DOT fu DOT is DOT saga-u DOT ac DOT jp>
To: gnu-win32 AT cygnus DOT com
Cc: jfmiller AT polymail DOT cpunix DOT calpoly DOT edu

John Miller <jfmiller AT polymail DOT cpunix DOT calpoly DOT edu> 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 <fjh AT cs DOT mu DOT oz DOT au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh AT 128 DOT 250 DOT 37 DOT 3         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019