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

UPDATE: SOLVED - thanks to syphilis and ikegami. See solution write up below at Re: MingW C for XS in ActiveState.

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 syphilis (Archbishop) on Feb 19, 2010 at 04:42 UTC
    ... it compiles under MSVC++ and under MingW (if I run it 'manually' instead of via the 'nmake' Makefile)

    I don't see why LockWorkStation.o fails to be built by the Makefile .... it's a bit weird.
    But that old version of nmake that you're using is known to be flakey. Try getting a newer version of nmake, or (better still, imo) install dmake from CPAN.

    If you do want to switch to dmake, you may need to make sure that nmake is hidden from view - by (eg) removing it from the path, or deleting it. (Otherwise, perl might still continue to generate the Makefile for nmake, instead of for dmake.)

    Cheers,
    Rob
Re: MingW C for XS in ActiveState
by ikegami (Patriarch) on Feb 19, 2010 at 07:08 UTC

    Aren't you suppose to use dmake with mingw?

    Either way, mixing ActiveState (built with MS tools) and non-MS tools isn't the best way to go.

      Aren't you suppose to use dmake with mingw?

      Shouldn't matter, afaik - so long as $Config{make} matches the make utility you're using, it should be fine.

      However, I too would prefer to use dmake with MinGW and nmake with MSVC++ .... just in case :-)

      I believe (untested) that you do need to use dmake if you want to build perl itself with MinGW, whereas you can build perl using either dmake or nmake with MSVC++ - and thats' something I *have* tested recently.

      Cheers,
      Rob
        Something didn't ring through with what I was saying, which is why I asked it as a question. thanks.
Re: MingW C for XS in ActiveState
by VinsWorldcom (Prior) on Feb 19, 2010 at 15:26 UTC

    ++ for syphilis and ikegami. Your comments forced me to go back, install dmake (which I didn't think I needed) and learn a valuable lesson not learned after reading Compiling C/C++ based Modules under ActiveState using MinGW (ironically posted by syphilis).

    SOLUTION:

    Since I do some C work, I already have Dev-Cpp (http://bloodshed.net) installed (thus MingW gcc in C:\Dev-cpp\bin in my path). However, the 'make.exe' installed with Dev-cpp is not liked by ActiveState Perl - it asks for 'dmake.exe' specifically; however, we know MS 'nmake.exe' works "well" also. I downloaded MS 'nmake.exe' to be able to do the:

    perl Makefile.PL make make test make install

    and the Microsoft 'nmake.exe' (in place of 'make' in the above example) works fine with ActiveState with or without a C compiler installed (as one isn't needed) for simple Perl modules (that is, ones without XS C compile required). However for more complicated modules - that is - ones that require a C compiler for XS components, it *IS* essential that you match your make utility and your C compiler.

    • dmake, MingW (gcc.exe)
    • nmake, MS VC++ (cl.exe)

    After taking the comments into consideration, I did a:

    ppm install dmake

    I then moved 'nmake.exe' out of my path. I added 'C:\Perl\site\bin' (where 'dmake.exe' was installed) to the end of my path (which already had 'C:\Dev-cpp\bin' among other things). Now, a:

    perl Makefile.PL dmake dmake test dmake install

    Worked fine - using the C:\Perl\Site\bin\dmake.exe and C:\Dev-cpp\bin\* C utilities (compiler, linker, DLL tools). My XS module compiled fine - as expected.

    LESSON:

    When doing module compiles involving C code, make (pun intended) sure your make utility and C compiler "match". That is:

    • dmake, MingW (gcc.exe)
    • nmake, MS VC++ (cl.exe)

    seem to work best. Note, these are probably not the only make/C utilities available, they are just the combinations I've 'tested' during this experience.

      Or
      ppm install MinGW dmake
      and be finished
      it *IS* essential that you match your make utility and your C compiler

      Actually, it's essential that you match your make utility with what perl -V:make reports.

      I've just built PDL-2.4.6 and a couple of other XS modules using nmake and MinGW without any problems. The tricky bit when building with gcc and nmake on ActivePerl would be making sure that perl -V:make reports 'nmake', not 'dmake'. (I actually didn't manage to achieve that with AS build 1007, though I think it could be done quite readily with some of the earlier AS builds.)

      Anyway ... good that you've now got things working, and in a sane and reliable way.

      Cheers,
      Rob