[Mingw-users] undefined reference to `__chkstk_ms'

Back to archive index
Rastislav Stanik mingw****@rasto*****
Mon May 27 17:05:29 JST 2019


Hi,

I've hit a problem when compiling my project with
gcc --version
gcc (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project) 8.1.0

I'm trying to build a 32-bit (using -m32) shared library that uses PCRE
(Perl Compatible Regular Expressions library) compiled by myself using the
same compiler. At linking stage I get a report about missing symbol
__chkstk_ms:

{MinGW-root}/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib32/libmingw32.a(lib32_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x18d):
undefined reference to `__chkstk_ms'

Reference to __chkstk_ms() is added by compiler when some function declares
local variables exceeding page size (~4k). In my case the function that
exceeds the limit is in PRCE, so I cannot simply work around it in my code.
The function __chkstk_ms() is provided by libgcc.a located in directory

  {MinGW-root}/lib/gcc/x86_64-w64-mingw32/8.1.0/32/

So if I add linking of that libgcc.a then the linking stage succeeds. But I
also have to ensure that libgcc.a is in link search path.

Questions:
- why the compiler does not add libgcc.a by itself when it added
__chkstk_ms() by itself?
- if I add -lgcc, why do I also have to add path with -L? Shouldn't the
directory be in the default linker search path?
- is there a solution that will keep working after next release of
MinGW/GCC when the path to libgcc changes?
--
	bye
		rastos



More information about the MinGW-Users mailing list
Back to archive index