Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Baffling compilation errors from Strawberry Perl

by no longer just digit (Beadle)
on Feb 20, 2021 at 04:25 UTC ( [id://11128586]=perlquestion: print w/replies, xml ) Need Help??

no longer just digit has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting quite baffling compilation errors from Strawberry Perl as seen here.

The errors look like this:

In file included from Libdeflate.xs:3: C:\STRAWB~1\perl\lib\CORE/XSUB.h:615:21: error: 'PerlMem_malloc' undec +lared here (not in a function); did you mean 'Perl_malloc'? # define malloc PerlMem_malloc ^~~~~~~~~~~~~~ C:\STRAWB~1\perl\lib\CORE/XSUB.h:615:21: note: in definition of macro +'malloc' # define malloc PerlMem_malloc ^~~~~~~~~~~~~~ C:\STRAWB~1\perl\lib\CORE/XSUB.h:618:19: error: 'PerlMem_free' undecla +red here (not in a function); did you mean 'Perl_sv_free'? # define free PerlMem_free ^~~~~~~~~~~~ C:\STRAWB~1\perl\lib\CORE/XSUB.h:618:19: note: in definition of macro +'free' # define free PerlMem_free ^~~~~~~~~~~~ gmake: *** [Makefile:340: Libdeflate.o] Error 1 -> FAIL Installing Gzip-Libdeflate-0.01_01.tar.gz failed. See C:\Users +\ben\.cpanm\work\1613793219.7300\build.log for details. Retry with -- +force to force install it.

On my Perl XSUB.h defines free as above, but I don't understand what this error even means, since it is coming from a #define line where what is on the right shouldn't matter.

I've tried everything I can think of to work out what is happening, but I'm completely stumped.

Replies are listed 'Best First'.
Re: Baffling compilation errors from Strawberry Perl
by syphilis (Archbishop) on Feb 20, 2021 at 06:19 UTC
    Hi,

    This patch works for me:
    --- libdeflate-one.c_orig 2021-02-20 17:12:44 +1100 +++ libdeflate-one.c 2021-02-20 17:23:26 +1100 @@ -27,6 +27,10 @@ /* #include "lib_common.h" */ +#ifdef WIN32 +#undef malloc +#undef free +#endif #ifndef LIB_LIB_COMMON_H #define LIB_LIB_COMMON_H
    This issue with free/malloc on Windows is not unique to Gzip::Libdeflate.
    Update: Added "#ifdef WIN32" to provide portability.

    'Nother Update:

    On my Perl XSUB.h defines free as above, but I don't understand what this error even means, since it is coming from a #define line where what is on the right shouldn't matter.

    Aaah ... but it does matter in libdeflate-one.c, where free (and malloc) need to be implemented according to the stdlib.h specification, not according to perl's (re)definition of them.
    By undef'ing those 2 symbols, we ensure that the stdlib.h implementations are used.

    Cheers,
    Rob

      That seems to work.

      Aaah ... but it does matter in libdeflate-one.c, where free (and malloc) need to be implemented according to the stdlib.h specification, not according to perl's (re)definition of them. By undef'ing those 2 symbols, we ensure that the stdlib.h implementations are used.

      Thank you for these insights.

      I tried any number of things, but the

      #undef malloc

      idea was not one of them. I understand that XSUB.h or another Perl header file redefines malloc into a Perl function or macro which takes two arguments, but the thing which I still find confusing is that the error messages appear to be coming from XSUB.h yet the actual error is occurring within my C file libdeflate-one.c, so the error messages seem to assume that the error occurred on another line from where they actually did. Since the compiler is gcc it's not the fault of Microsoft Windows.

      Edit

      I have just spent a little time debugging another XS module on Strawberry Perl (for details see this diff) and I'd like to point out that

      #undef realloc

      and probably

      #undef calloc

      are also needed if the C code is using those as well.

      There is no error message from Windows, and the GDB backtrace looks like this:

      ok 1 - use Gzip::Zopfli; Thread 1 received signal SIGSEGV, Segmentation fault. 0x00000000658f0794 in perl532!Perl_drand48_r () from C:\Strawberry\per +l\bin\perl532.dll (gdb) bt #0 0x00000000658f0794 in perl532!Perl_drand48_r () from C:\Strawberry +\perl\bin\perl532.dll #1 0x0000000067948d63 in ?? () from C:\Users\ben\Documents\Gzip-Zopfl +i-0.01\blib\arch\auto\Gzip\Zopfli\Zopfli.xs.dll #2 0x000000006794985a in ?? () from C:\Users\ben\Documents\Gzip-Zopfl +i-0.01\blib\arch\auto\Gzip\Zopfli\Zopfli.xs.dll #3 0x0000000067949964 in ?? () from C:\Users\ben\Documents\Gzip-Zopfl +i-0.01\blib\arch\auto\Gzip\Zopfli\Zopfli.xs.dll #4 0x0000000067949bf4 in ?? () from C:\Users\ben\Documents\Gzip-Zopfl +i-0.01\blib\arch\auto\Gzip\Zopfli\Zopfli.xs.dll #5 0x000000006587b1e2 in perl532!Perl_clear_defarray () from C:\Straw +berry\perl\bin\perl532.dll #6 0x00000000658dfdd6 in perl532!Perl_runops_standard () from C:\Stra +wberry\perl\bin\perl532.dll #7 0x0000000065890eb7 in perl_run () from C:\Strawberry\perl\bin\perl +532.dll #8 0x00000000658f3ac8 in perl532!RunPerl () from C:\Strawberry\perl\b +in\perl532.dll #9 0x00000000004013c7 in ?? () #10 0x00000000004014fb in ?? () #11 0x00007ffe753d7034 in KERNEL32!BaseThreadInitThunk () from C:\WIND +OWS\System32\kernel32.dll #12 0x00007ffe764bd241 in ntdll!RtlUserThreadStart () from C:\WINDOWS\ +SYSTEM32\ntdll.dll #13 0x0000000000000000 in ?? () Backtrace stopped: previous frame inner to this frame (corrupt stack?)

      I found out what was wrong by Googling and puzzling over this bug report. It took a few attempts before I thought of this realloc problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11128586]
Approved by haukex
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found