VinsWorldcom has asked for the wisdom of the Perl Monks concerning the following question:

I'm using ActiveState Perl and the MingW C compiler as supplied with Dev-cpp.

Admin://{C} # perl -v This is perl, v5.10.1 built for MSWin32-x86-multi-thread (with 2 registered patches, see perl -V for more detail) ... Admin://{C} # gcc -dumpversion 3.4.2

I'm trying to compile an XS module that compiles fine on another system that uses MS Visual Studio instead of MingW.

It seems like the 'nmake' is "printing" the gcc step, but not actually executing it as no '.o' file is created. If I run nmake, it bombs out, but if I then manually re-run the gcc step, the '.o' file is created and a subsequent 'nmake' works fine.

Admin://{C} # perl Makefile.PL Set up gcc environment - 3.4.2 (mingw-special) Checking if your kit is complete... Looks good Writing Makefile for Win32::LockWorkStation Admin://{C} # nmake Microsoft (R) Program Maintenance Utility Version 1.50 Copyright (c) Microsoft Corp 1988-94. All rights reserved. cp lib/Win32/LockWorkStation.pm blib\lib\Win32\LockWorkStation.pm C:\Perl\bin\perl.exe C:\Perl\site\lib\ExtUtils\xsubpp -typema +p C:\Perl\ lib\ExtUtils\typemap LockWorkStation.xs > LockWorkStation.xsc && C:\P +erl\bin\pe rl.exe -MExtUtils::Command -e "mv" -- LockWorkStation.xsc LockWorkStat +ion.c c:/Dev-Cpp/bin/gcc.exe -c -DNDEBUG -DWIN32 -D_CONSOLE -DNO_ +STRICT -DH AVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLIC +IT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -DHASATTRIBUTE + -fno-stri ct-aliasing -mms-bitfields -O2 -DVERSION=\"0.01\" -DXS_VERSION=\"0 +.01\" "-I C:\Perl\lib\CORE" -D_WIN32_WINNT=0x0500 LockWorkStation.c Running Mkbootstrap for Win32::LockWorkStation () C:\Perl\bin\perl.exe -MExtUtils::Command -e "chmod" -- 644 Loc +kWorkStati on.bs C:\Perl\bin\perl.exe -MExtUtils::Mksymlists -e "Mksymlists('N +AME'=>\"Wi n32::LockWorkStation\", 'DLBASE' => 'LockWorkStation', 'DL_FUNCS' => { + }, 'FUNC LIST' => [], 'IMPORTS' => { }, 'DL_VARS' => []);" Set up gcc environment - 3.4.2 (mingw-special) dlltool --def LockWorkStation.def --output-exp dll.exp c:\Dev-Cpp\bin\g++.exe -o blib\arch\auto\Win32\LockWorkStation +\LockWorkS tation.dll -Wl,--base-file -Wl,dll.base -mdll -L"C:\Perl\lib\CORE" Loc +kWorkStati on.o -Wl,--image-base,0x1b000000 C:\Perl\lib\CORE\perl510.lib c:\Dev- +Cpp\lib\li buser32.a c:\Dev-Cpp\lib\libkernel32.a c:\Dev-Cpp\lib\libuser32.a c:\D +ev-Cpp\lib \libgdi32.a c:\Dev-Cpp\lib\libwinspool.a c:\Dev-Cpp\lib\libcomdlg32.a +c:\Dev-Cpp \lib\libadvapi32.a c:\Dev-Cpp\lib\libshell32.a c:\Dev-Cpp\lib\libole32 +.a c:\Dev- Cpp\lib\liboleaut32.a c:\Dev-Cpp\lib\libnetapi32.a c:\Dev-Cpp\lib\libu +uid.a c:\D ev-Cpp\lib\libws2_32.a c:\Dev-Cpp\lib\libmpr.a c:\Dev-Cpp\lib\libwinmm +.a c:\Dev- Cpp\lib\libversion.a c:\Dev-Cpp\lib\libodbc32.a c:\Dev-Cpp\lib\libodbc +cp32.a c:\ Dev-Cpp\lib\libmsvcrt.a dll.exp g++.exe: LockWorkStation.o: No such file or directory NMAKE : fatal error U1077: 'C:\WINDOWS\system32\cmd.exe' : return code + '0x1' Stop. Admin://{C} # ls LockWorkStation.* Directory of C:\Documents and Settings\Admin\My Documents\tmp\Win32-L +ockWor kStation-0.01 LockWorkStation.bs LockWorkStation.def LockWorkStation.c LockWorkStation.xs 4 File(s) 3,846 bytes Admin://{C} # c:/Dev-Cpp/bin/gcc.exe -c -DNDEBUG -DWIN32 -D +_CONSO LE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN +_INC -DPER L_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READ +FIX -DHASA TTRIBUTE -fno-strict-aliasing -mms-bitfields -O2 -DVERSION=\"0.01\" + -DXS_VER SION=\"0.01\" "-IC:\Perl\lib\CORE" -D_WIN32_WINNT=0x0500 LockWorkSta +tion.c Admin://{C} # ls LockWorkStation.* Directory of C:\Documents and Settings\Admin\My Documents\tmp\Win32-L +ockWor kStation-0.01 LockWorkStation.bs LockWorkStation.def LockWorkStation.xs LockWorkStation.c LockWorkStation.o 5 File(s) 7,913 bytes Admin://{C} #

I've done a lot of Google searching but came up empty. I know the XS code is good because it compiles under MSVC++ and under MingW (if I run it 'manually' instead of via the 'nmake' Makefile). Is there something in the 'perl Makefile.PL' step I'm missing - is there something that needs to be in the Makefile?

Replies are listed 'Best First'.
Re: MingW C for XS in ActiveState
by desemondo (Hermit) on Feb 20, 2010 at 10:12 UTC
    I'm not sure if this is the cause of your particular issue, but I do know that the makefile is created differently depending on whether Perl thinks you're using nmake/MSVC instead of dmake/gcc.

    Run C:\>perl -V:cc and check its output. If it returns the path to nmake, that is almost certainly wrong if you are wanting to use the MingW gcc tools.
    To Fix, move nmake to somewhere that is not in your PATH environment variable, {update} and ensure that the MingW tools is in your PATH. {/update} then rerun  C:\>perl -V:cc and it should return the path to gcc.exe. (may need to run it a second or third time sometimes until it does...)

    Once that is configured correctly, just follow the standard mantra :
    c:\temp>perl makefile.pl c:\temp>dmake c:\temp>dmake test c:\temp>dmake install
    (Also, i'd recommend using the gcc tools provided in the kit: ppm install mingw rather than downloading the tools individually as less fiddling is needed... The only hitch you might run into is that C:\perl\site\bin may not be in your PATH, in which case, just add it via System Properties > Advanced tab > Environment variables)

    Updated: clarified post, and added extra detail...