Has anyone here has success building C++ based Perl-extensions under, because I'm having a heckuva time doing it. My XS seems fine, but then when I try to do the build I get all kinds of syntax errors when the compiler tries to process several of the Perl header files. I'm using Microsoft Visual Studio .NET 2003 on Windows XP SP 2. Here's a sample of the output:
F:\Quality>nmake /F Makefile Microsoft (R) Program Maintenance Utility Version 7.10.3077 Copyright (C) Microsoft Corporation. All rights reserved. C:\perl_local\bin\perl.exe C:\perl_local\lib\ExtUtils\xsubpp - +noprototypes -C++ -hiertype -csuffix .cpp -typemap C:\perl_local\lib\ +ExtUtils\typemap Quality.xs > Quality.xsc && C:\perl_local\bin\perl. +exe -MExtUtils::Command -e mv Quality.xsc Quality.cpp cl -c -I. -nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CO +NSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED -DUSE_SITECUSTOMIZ +E -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSV +CRT_READFIX -MD -Zi -DNDEBUG -O1 -DVERSION=\"0.01\" -DXS_VERSION= +\"0.01\" "-IC:\perl_local\lib\CORE" Quality.cpp Quality.cpp C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +18) : error C2039: 'PerlSIO_clearerr' : is not a member of 'operator` +`global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +18) : error C2873: 'PerlSIO_clearerr' : symbol cannot be used in a us +ing-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +18) : error C2039: 'PerlSIO_fclose' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +18) : error C2873: 'PerlSIO_fclose' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +18) : error C2039: 'PerlSIO_feof' : is not a member of 'operator``glo +bal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +18) : error C2873: 'PerlSIO_feof' : symbol cannot be used in a using- +declaration
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +19) : error C2039: 'PerlSIO_ferror' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +19) : error C2873: 'PerlSIO_ferror' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +19) : error C2039: 'PerlSIO_fflush' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +19) : error C2873: 'PerlSIO_fflush' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +20) : error C2039: 'PerlSIO_fgetpos' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +20) : error C2873: 'PerlSIO_fgetpos' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +20) : error C2039: 'PerlSIO_fopen' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +20) : error C2873: 'PerlSIO_fopen' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +21) : error C2039: 'PerlSIO_fputc' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +21) : error C2873: 'PerlSIO_fputc' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +21) : error C2039: 'PerlSIO_fputs' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +21) : error C2873: 'PerlSIO_fputs' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +22) : error C2039: 'PerlSIO_fread' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +22) : error C2873: 'PerlSIO_fread' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +22) : error C2039: 'PerlSIO_freopen' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +22) : error C2873: 'PerlSIO_freopen' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +23) : error C2039: 'PerlSIO_fseek' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +23) : error C2873: 'PerlSIO_fseek' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +23) : error C2039: 'PerlSIO_fsetpos' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +23) : error C2873: 'PerlSIO_fsetpos' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +23) : error C2039: 'PerlSIO_ftell' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +23) : error C2873: 'PerlSIO_ftell' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +24) : error C2039: 'PerlSIO_fwrite' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +24) : error C2873: 'PerlSIO_fwrite' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +24) : error C2039: 'PerlSIO_getc' : is not a member of 'operator``glo +bal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +24) : error C2873: 'PerlSIO_getc' : symbol cannot be used in a using- +declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +28) : error C2039: 'PerlLIO_rename' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +28) : error C2873: 'PerlLIO_rename' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +29) : error C2039: 'PerlSIO_setbuf' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +29) : error C2873: 'PerlSIO_setbuf' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +29) : error C2039: 'PerlSIO_setvbuf' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +29) : error C2873: 'PerlSIO_setvbuf' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +30) : error C2039: 'PerlSIO_tmpfile' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +30) : error C2873: 'PerlSIO_tmpfile' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +30) : error C2039: 'PerlLIO_tmpnam' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +30) : error C2873: 'PerlLIO_tmpnam' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +31) : error C2039: 'PerlSIO_ungetc' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +31) : error C2873: 'PerlSIO_ungetc' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +31) : error C2039: 'PerlSIO_vprintf' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio( +31) : error C2873: 'PerlSIO_vprintf' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(19) : error C2039: 'PerlProc_abort' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(19) : error C2873: 'PerlProc_abort' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(22) : error C2039: 'PerlProc_exit' : is not a member of 'operator``g +lobal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(22) : error C2873: 'PerlProc_exit' : symbol cannot be used in a usin +g-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(22) : error C2039: 'PerlMem_free' : is not a member of 'operator``gl +obal namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(22) : error C2873: 'PerlMem_free' : symbol cannot be used in a using +-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(22) : error C2039: 'PerlEnv_getenv' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(22) : error C2873: 'PerlEnv_getenv' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(23) : error C2039: 'PerlMem_malloc' : is not a member of 'operator`` +global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(23) : error C2873: 'PerlMem_malloc' : symbol cannot be used in a usi +ng-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(25) : error C2039: 'PerlMem_realloc' : is not a member of 'operator` +`global namespace''' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdlib +(25) : error C2873: 'PerlMem_realloc' : symbol cannot be used in a us +ing-declaration C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutilit +y(136) : error C2766: explicit specialization; 'std::iterator_traits< +std::_Bool>' has already been defined C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutilit +y(258) : error C2084: function 'std::_Scalar_ptr_iterator_tag std::_P +tr_cat(std::_Bool *,std::_Bool *)' already has a body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\xutility(245) : see previous definition of '_Ptr_cat' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutilit +y(264) : error C2084: function 'std::_Scalar_ptr_iterator_tag std::_P +tr_cat(const std::_Bool *,std::_Bool *)' already has a body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\xutility(251) : see previous definition of '_Ptr_cat' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : '(' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\streambuf(390) : see reference to class template instantiation 'std: +:basic_streambuf<_Elem,_Traits>' being compiled C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2143: syntax error : missing ')' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2143: syntax error : missing ';' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(362) : error C2334: unexpected token(s) preceding '{'; skipping ap +parent function body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : '(' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\streambuf(394) : see reference to class template instantiation 'std: +:basic_streambuf<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2143: syntax error : missing ')' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2143: syntax error : missing ';' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(362) : error C2334: unexpected token(s) preceding '{'; skipping ap +parent function body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : '(' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\streambuf(395) : see reference to class template instantiation 'std: +:basic_streambuf<_Elem,_Traits>' being compiled with [ _Elem=wchar_t, _Traits=std::char_traits<wchar_t> ] C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2143: syntax error : missing ')' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2143: syntax error : missing ';' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(361) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\streamb +uf(362) : error C2334: unexpected token(s) preceding '{'; skipping ap +parent function body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(491) : warning C4003: not enough actual parameters for macro 'PerlLI +O_write' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : '(' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\ostream(545) : see reference to class template instantiation 'std::b +asic_ostream<_Elem,_Traits>' being compiled C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2143: syntax error : missing ')' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2528: 'Perl_ILIO_ptr' : pointer to reference is illega +l C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2143: syntax error : missing ';' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(492) : error C2334: unexpected token(s) preceding '{'; skipping appa +rent function body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : '(' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\ostream(561) : see reference to class template instantiation 'std::b +asic_ostream<_Elem,_Traits>' being compiled with [ _Elem=wchar_t, _Traits=std::char_traits<wchar_t> ] C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2143: syntax error : missing ')' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2528: 'Perl_ILIO_ptr' : pointer to reference is illega +l C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2143: syntax error : missing ';' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(492) : error C2334: unexpected token(s) preceding '{'; skipping appa +rent function body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(574) : warning C4530: C++ exception handler used, but unwind semanti +cs are not enabled. Specify /EHsc C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : '(' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include +\ostream(603) : see reference to class template instantiation 'std::b +asic_ostream<_Elem,_Traits>' being compiled with [ _Elem=char, _Traits=std::char_traits<char> ] C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2143: syntax error : missing ')' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2528: 'Perl_ILIO_ptr' : pointer to reference is illega +l C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2143: syntax error : missing ';' before '->' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(490) : error C2059: syntax error : ')' C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(492) : error C2334: unexpected token(s) preceding '{'; skipping appa +rent function body C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream +(604) : fatal error C1903: unable to recover from previous error(s); +stopping co mpilation NMAKE : fatal error U1077: 'cl' : return code '0x2' Stop.
I can't post the actual code here, but it is very similar to the baby examaple I posted here

--DrWhy

"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."


In reply to Building C++ extensions under MSVC? by DrWhy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.