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

Could anyone of you help me in solving an issue I am facing while linking C++ lib and headers with Perl using H2xs?
I have done the following:
1. First I write a C source file and its header file.
2. Create the new module using “c:/perl/bin/h2xs -n Remote::Connection
3. I adjust the Makefile.pl by adding the following line:
$CC = 'cl';
CC => $CC,
LD => '$(CC)',
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
INC => ' -I/C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include -I/C:\Program Files\Microsoft Visual Studio 8\VC\include', # e.g., '-I. -I/usr/include/other'
'OBJECT' => '$(O_FILES)',
4. Do some changes in default Connection.pm file (Added the function which I need to perform).
5. Create test.pl file
6. Add C++ code in Connection.xs
7. I have placed the project C++ Source file n header file in c: /perl/bin/Remote::Connection
8. In the cmd prompt I say c:/perl/bin/
Remote::Connection /perl makefile.pl
9. When I run nmake on the cmd prompt I get the following error msg:
Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
cp lib/Remote/Connection.pm blib\lib\Remote\Connection.pm
C:\Perl\bin\perl.exe C:\Perl\lib\ExtUtils\xsubpp -typemap C:\Perl\lib\ExtUtils\typemap -typemap typemap Connection.xs > Connection.xsc && C:\Perl\bin\ perl.exe -MExtUtils::Command -e mv Connection.xsc Connection.c -I/C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\include -I/C:\Program Files\Microsoft Visual Studio 8\VC\include -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -RL_IMPLICIT_CONTE XT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -MD -Zi -DNDEBUG -O1 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-IC:\Perl\lib\CORE" Connection.c
cl : Command line warning D9024 : unrecognized source file type 'Files\Microsoft ', object file assumed
cl : Command line warning D9027 : source file 'Files\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed
cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object file assumed
cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '8\VC\atlmfc\include', object file assumed
cl : Command line warning D9027 : source file '8\VC\atlmfc\include' ignored
cl : Command line warning D9024 : unrecognized source file type 'Files\Microsoft', object file assumed
cl : Command line warning D9027 : source file 'Files\Microsoft' ignored
cl : Command line warning D9024 : unrecognized source file type 'Visual', object
file assumed cl : Command line warning D9027 : source file 'Visual' ignored
cl : Command line warning D9024 : unrecognized source file type 'Studio', object
file assumed cl : Command line warning D9027 : source file 'Studio' ignored
cl : Command line warning D9024 : unrecognized source file type '8\VC\include',object file assumed
cl : Command line warning D9027 : source file '8\VC\include' ignored Connection.c
C:\Program Files\Microsoft Visual Studio 8\VC\ATLMFC\INCLUDE\afxv_w32.h(16) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\c l.EXE"' : return code '0x2'
Stop.
Is there any thing that I am missing while specifying the path of the lib.
Please let me know your comments.
How do I link all the MFC apps (Vc++ Header files, lib and Dll) with h2xs (Command line).

Replies are listed 'Best First'.
Re: Any help on Perl h2xs would appreciate
by Corion (Patriarch) on Feb 17, 2009 at 09:18 UTC

    You need to properly quote your paths, as they contain whitespace, for example Program Files. Likely you should just leave the INC entries (etc) alone and let ExtUtils::MakeMaker fill them in for you, but if you insist on manually filling them, maybe the following works:

    ... INC => ' "-I/C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\incl +ude" "-I/C:\Program Files\Microsoft Visual Studio 8\VC\include"', ...
      As per your inputs i removed white space and let the ExtUtils::MakeMaker to fill them
      . I get the following error msg:
      C:\Perl\bin\Remote-Connection>nmake
      Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
      Copyright (C) Microsoft Corporation. All rights reserved.
      cp lib/Remote/Connection.pm blib\lib\Remote\Connection.pm C:\Perl\bin\perl.exe C:\Perl\lib\ExtUtils\xsubpp -typemap C:\Perl\lib\ExtUtils\typemap -typemap typemap Connection.xs > Connection.xsc && C:\Perl\bin\ perl.exe -MExtUtils::Command -e mv Connection.xsc Connection.c
      cl.exe -c -I. -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE
      -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_I
      MPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX -MD -Zi -
      DNDEBUG -O1 -DVERSION=\"0.01\" -DXS_VERSION=\"0.01\" "-IC:\Perl\lib\CORE"
      Connection.c
      Connection.c
      C:\Perl\bin\Remote-Connection\afxv_w32.h(178) : error C2371: 'HKEY' : redefinition; different basic types C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\windef.h(246) : see declaration of 'HKEY'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(227) : error C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(228) : error
      C2085: 'GetWindowTask' : not in formal parameter list
      C:\Perl\bin\Remote-Connection\afxv_w32.h(228) : error
      C2143: syntax error : missing ';' before '{'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(235) : error C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(236) : error
      C2085: 'GetNextWindow' : not in formal parameter list
      C:\Perl\bin\Remote-Connection\afxv_w32.h(236) : error C2143: syntax error : missing ';' before '{'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(242) : error
      C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(248) : error
      C2085: 'DrawState' : not in formal parameter list
      C:\Perl\bin\Remote-Connection\afxv_w32.h(248) : error
      C2143: syntax error : missing ';' before '{'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(256) : error
      C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(257) : error
      C2085: 'AfxDrawStatusTextA' : not in formal parameter list
      C:\Perl\bin\Remote-Connection\afxv_w32.h(258) : error
      C2061: syntax error : identifier 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(260) : error
      C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(265) : error
      C2085: 'DrawStatusText' :not in formal parameter list
      C:\Perl\bin\Remote-Connection\afxv_w32.h(265) : error
      C2143: syntax error : missing ';' before '{'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(271) : error
      C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(271) : error
      C2082: redefinition of formal parameter 'FreeResource'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(271) : error
      C2143: syntax error : missing ';' before '{'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(274) : error
      C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afxv_w32.h(274) : error
      C2085: 'UnlockResource' :not in formal parameter list
      C:\Perl\bin\Remote-Connection\afxv_w32.h(274) : error
      C2143: syntax error : missing ';' before '{'
      C:\Perl\bin\Remote-Connection\afx.h(193) : error C2061:
      syntax error : identifier 'CObject'
      C:\Perl\bin\Remote-Connection\afx.h(193) : error C2059:
      syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(195) : error C2061:
      syntax error : identifier 'CException'
      C:\Perl\bin\Remote-Connection\afx.h(195) : error C2059:
      syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(196) : error C2061:
      syntax error : identifier 'CArchiveException'
      C:\Perl\bin\Remote-Connection\afx.h(196) : error C2059:
      syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(197) : error C2061:
      syntax error : identifier 'CFileException'
      C:\Perl\bin\Remote-Connection\afx.h(197) : error C2059:
      syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(198) : error C2061:
      syntax error : identifier 'CSimpleException'
      C:\Perl\bin\Remote-Connection\afx.h(198) : error C2059:
      syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(199) : error C2061:
      syntax error : identifier 'CMemoryException'
      C:\Perl\bin\Remote-Connection\afx.h(199) : error
      C2059: syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(200) : error
      C2061: syntax error :
      identifier 'CNotSupportedException'
      C:\Perl\bin\Remote-Connection\afx.h(200) : error
      C2059:
      syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(201) : error
      C2061:
      syntax error : identifier 'CInvalidArgException' C:\Perl\bin\Remote-Connection\afx.h(201) : error C2059:
      syntax error : ';' C:\Perl\bin\Remote-Connection\afx.h(203) : error C2061: syntax error : identifier 'CFile'
      C:\Perl\bin\Remote-Connection\afx.h(203) : error C2059: syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(204) : error C2061: syntax error : identifier 'CStdioFile'
      C:\Perl\bin\Remote-Connection\afx.h(204) : error C2059: syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(205) : error C2061: syntax error : identifier 'CMemFile'
      C:\Perl\bin\Remote-Connection\afx.h(205) : error C2059: syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(211) : error C2061: syntax error : identifier 'CArchive'
      C:\Perl\bin\Remote-Connection\afx.h(211) : error C2059: syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(212) : error C2061: syntax error : identifier 'CDumpContext'
      C:\Perl\bin\Remote-Connection\afx.h(212) : error C2059: syntax error : ';'
      C:\Perl\bin\Remote-Connection\afx.h(261) : error C2059: syntax error : '}'
      C:\Perl\bin\Remote-Connection\afx.h(262) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(364) : error C2054: expected '(' to follow 'inline'
      C:\Perl\bin\Remote-Connection\afx.h(364) : error C2143: syntax error : missing ')' before '...'
      C:\Perl\bin\Remote-Connection\afx.h(364) : error C2085: 'AfxTrace' : not in formal parameter list
      C:\Perl\bin\Remote-Connection\afx.h(364) : error C2143: syntax error : missing ';' before '...'
      C:\Perl\bin\Remote-Connection\afx.h(364) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(444) : error C2143: syntax error : missing ')' before '='
      C:\Perl\bin\Remote-Connection\afx.h(444) : error C2072: 'AfxInitialize' : initialization of a function
      C:\Perl\bin\Remote-Connection\afx.h(444) : warning C4142: benign redefinition of type
      C:\Perl\bin\Remote-Connection\afx.h(444) : error
      C2370: 'DWORD' : redefinition;different storage class C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\windef.h(151) : see declaration of 'DWORD'
      C:\Perl\bin\Remote-Connection\afx.h(444) : error C2146: syntax error : missing ';' before identifier 'dwVersion'
      C:\Perl\bin\Remote-Connection\afx.h(444) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(453) : error C2143: syntax error : missing ')' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(453) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(453) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(455) : error C2061: syntax error : identifier 'AFX_CLASSINIT'
      C:\Perl\bin\Remote-Connection\afx.h(455) : error C2059: syntax error : '}'
      C:\Perl\bin\Remote-Connection\afx.h(463) : error C2061: syntax error : identifier 'CObject'
      C:\Perl\bin\Remote-Connection\afx.h(467) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(471) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(472) : error C2143: syntax error : missing ')' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(472) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(472) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(472) : error C2143: syntax error : missing '{' before 'const'
      C:\Perl\bin\Remote-Connection\afx.h(472) : warning C4091: ' ' : ignored on leftof 'const int' when no variable is declared
      C:\Perl\bin\Remote-Connection\afx.h(475) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(476) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(476) : warning C4028: formal parameter 1 different from declaration
      C:\Perl\bin\Remote-Connection\afx.h(477) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(477) : error C2373: 'CreateObject' : redefinition; different type modifiers
      C:\Perl\bin\Remote-Connection\afx.h(471) : see declaration of 'CreateObject'
      C:\Perl\bin\Remote-Connection\afx.h(478) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(478) : error
      C2373: 'CreateObject' : redefinition; different type modifiers
      C:\Perl\bin\Remote-Connection\afx.h(471) : see declaration of 'CreateObject'
      C:\Perl\bin\Remote-Connection\afx.h(481) : error C2143: syntax error : missing ')' before '&'
      C:\Perl\bin\Remote-Connection\afx.h(481) : error C2143: syntax error : missing '{' before '&'
      C:\Perl\bin\Remote-Connection\afx.h(481) : error C2059: syntax error : '&'
      C:\Perl\bin\Remote-Connection\afx.h(481) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(482) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(482) : error C2143: syntax error : missing ')' before '&'
      C:\Perl\bin\Remote-Connection\afx.h(482) : error C2143: syntax error : missing '{' before '&'
      C:\Perl\bin\Remote-Connection\afx.h(482) : error C2059: syntax error : '&'
      C:\Perl\bin\Remote-Connection\afx.h(482) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(485) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(486) : error C2143: syntax error : missing '{' before '*'
      C:\Perl\bin\Remote-Connection\afx.h(487) : error C2059: syntax error : '}'
      C:\Perl\bin\Remote-Connection\afx.h(496) : error C2143: syntax error : missing ')' before '='
      C:\Perl\bin\Remote-Connection\afx.h(496) : error C2072: 'AfxThrowArchiveException' : initialization of a function
      C:\Perl\bin\Remote-Connection\afx.h(496) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(497) : error C2143: syntax error : missing ')' before '='
      C:\Perl\bin\Remote-Connection\afx.h(497) : error C2072: 'AfxThrowFileException': initialization of a function
      C:\Perl\bin\Remote-Connection\afx.h(498) : error C2182: 'LPCTSTR' : illegal useof type 'void'
      C:\Perl\bin\Remote-Connection\afx.h(498) : error C2040: 'LPCTSTR' : 'int' differs in levels of indirection from 'LPCSTR'
      C:\Perl\bin\Remote-Connection\afx.h(498) : error C2495: 'LPCTSTR' : '__declspec(noreturn)' can only be applied to function declarations or definitions
      C:\Perl\bin\Remote-Connection\afx.h(498) : error C2146: syntax error : missing ';' before identifier 'lpszFileName'
      C:\Perl\bin\Remote-Connection\afx.h(498) : error C2059: syntax error : ')'
      C:\Perl\bin\Remote-Connection\afx.h(504) : error C2054: expected '(' to follow'inline'
      C:\Perl\bin\Remote-Connection\afx.h(504) : fatal error C1003: error count exceeds 100; stopping compilation
      NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\BIN\cl.exe"' : return code '0x2'
      Stop.
        The thing to do in dealing with long lists of errors (such as the list that confronts you) is to deal with the very first error. Often, when that first error is fixed, the rest just disappear.

        The first error is:
        C:\Perl\bin\Remote-Connection\afxv_w32.h(178) : error C2371: 'HKEY' : +redefinition; different basic types C:\Program Files\Microsoft Visual + Studio 8\VC\PlatformSDK\include\windef.h(246) : see declaration of ' +HKEY'
        It looks to me that, at line 178 of C:\Perl\bin\Remote-Connection\afxv_w32.h, HKEY is being redefined, and your compiler is upset about that. So ... try to fix that first.

        One thing I've just noticed from your first post in this thread is that you've assigned LD => '$(CC)'. I think that's rather unusual for a Microsoft compiler. Normally I'm used to seeing link assigned to LD. I don't know much about C++, and I don't think this has anything to do with the immediate problem, but it's something to bear in mind if you experience linking errors later on.

        Cheers,
        Rob
        Something I would have mentioned in my last post if I had thought of it:
        With the 'cl' compiler, you'll need to let the compiler know that the source files are C++ (assuming they are, in fact written in C++). You can do that by setting CC to cl -TP
        As an alternative to that, renaming Connection.c to Connection.cpp might also work.
        Otherwise, cl will regard the source as being C code, and probably report numerous syntax errors.

        Cheers,
        Rob
Re: Any help on Perl h2xs would appreciate
by syphilis (Archbishop) on Feb 17, 2009 at 11:46 UTC