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

Hello, I'm trying to get Inline-CPP to work with Visual Studio 2012. This is on Windows 7, with StrawberryPerl installed. I need to use Visual Studio instead of GCC because I have to link to a closed source 3rd party library that has only been compiled with Visual Studio. When asked to choose the C++ compiler, it only gives me the option of g++ or -xc++. Any ideas on how to make it detect VC++?

C:\>cpan install Inline::CPP CPAN: CPAN::SQLite loaded ok (v0.204) CPAN: LWP::UserAgent loaded ok (v6.13) CPAN: Time::HiRes loaded ok (v1.9726) Fetching with LWP: http://cpan.strawberryperl.com/authors/01mailrc.txt.gz CPAN: YAML::XS loaded ok (v0.59) Fetching with LWP: http://cpan.strawberryperl.com/modules/02packages.details.txt.gz Fetching with LWP: http://cpan.strawberryperl.com/modules/03modlist.data.gz Creating database file ... Done! Running install for module 'Inline::CPP' Fetching with LWP: http://cpan.strawberryperl.com/authors/id/D/DA/DAVIDO/Inline-CPP-0.71. +tar.gz CPAN: Digest::SHA loaded ok (v5.95) Fetching with LWP: http://cpan.strawberryperl.com/authors/id/D/DA/DAVIDO/CHECKSUMS CPAN: Compress::Zlib loaded ok (v2.068) Checksum for C:\STRAWB~1\cpan\sources\authors\id\D\DA\DAVIDO\Inline-CP +P-0.71.tar .gz ok CPAN: Archive::Tar loaded ok (v2.04) CPAN: File::Temp loaded ok (v0.2304) CPAN: Parse::CPAN::Meta loaded ok (v1.4414) CPAN: CPAN::Meta loaded ok (v2.143240) CPAN: Module::CoreList loaded ok (v5.20150220) ---- Unsatisfied dependencies detected during ---- ---- DAVIDO/Inline-CPP-0.71.tar.gz ---- ExtUtils::CppGuess [build_requires] Running install for module 'ExtUtils::CppGuess' Fetching with LWP: http://cpan.strawberryperl.com/authors/id/E/ET/ETJ/ExtUtils-CppGuess-0 +.09.tar.gz Fetching with LWP: http://cpan.strawberryperl.com/authors/id/E/ET/ETJ/CHECKSUMS Checksum for C:\STRAWB~1\cpan\sources\authors\id\E\ET\ETJ\ExtUtils-Cpp +Guess-0.09 .tar.gz ok Configuring E/ET/ETJ/ExtUtils-CppGuess-0.09.tar.gz with Makefile.PL Checking if your kit is complete... Looks good Generating a dmake-style Makefile Writing Makefile for ExtUtils::CppGuess Writing MYMETA.yml and MYMETA.json ETJ/ExtUtils-CppGuess-0.09.tar.gz C:\Strawberry\perl\bin\perl.exe Makefile.PL -- OK Running make for E/ET/ETJ/ExtUtils-CppGuess-0.09.tar.gz cp lib/ExtUtils/CppGuess.pm blib\lib\ExtUtils\CppGuess.pm ETJ/ExtUtils-CppGuess-0.09.tar.gz C:\STRAWB~1\c\bin\dmake.exe -- OK Running make test "C:\Strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::H +arness" "- e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\ +arch')" t/ *.t t/001_load.t .......... 1/2 # EUMM:$VAR1 = { # 'dynamic_lib' => { # 'OTHERLDFLAGS' => ' -lstdc++ ' # }, # 'CCFLAGS' => ' -xc++ ' # }; # --- # MB:$VAR1 = { # 'extra_linker_flags' => ' -lstdc++ ', # 'extra_compiler_flags' => ' -xc++ ' # }; t/001_load.t .......... ok t/010_module_build.t .. ok t/011_makemaker.t ..... ok All tests successful. Files=3, Tests=4, 10 wallclock secs ( 0.06 usr + 0.02 sys = 0.08 CPU +) Result: PASS ETJ/ExtUtils-CppGuess-0.09.tar.gz C:\STRAWB~1\c\bin\dmake.exe test -- OK Running make install Installing C:\STRAWB~1\perl\site\lib\ExtUtils\CppGuess.pm Appending installation info to C:\STRAWB~1\perl\lib/perllocal.pod ETJ/ExtUtils-CppGuess-0.09.tar.gz C:\STRAWB~1\c\bin\dmake.exe install UNINST=1 -- OK DAVIDO/Inline-CPP-0.71.tar.gz Has already been unwrapped into directory C:\STRAWB~1\cpan\build\Inl +ine-CPP-0. 71-SnHQG0 Configuring D/DA/DAVIDO/Inline-CPP-0.71.tar.gz with Makefile.PL Warning: prerequisite Inline version 0.78 not found. at Makefile.PL li +ne 123. Warning: prerequisite Inline::C version 0.67 not found. at Makefile.PL + line 123. !!! PREREQUISITES NOT MET !!! at Makefile.PL line 35. What C++ compiler would you like to use? [g++ -xc++]

Replies are listed 'Best First'.
Re: Inline::CPP with Visual Studio
by davido (Cardinal) on Jun 25, 2015 at 01:34 UTC

    If I recall, ExtUtil::Cppguess determines how Perl was compiled. Well, strawberry Perl was compiled with a GNU toolchain, not MSVC++. ...and even if you did tell Inline::CPP to use MSVC++ instead, you may discover that the output is not byte compatible with how Perl was compiled. I don't know for sure, as I haven't tested such cross-toolchain situations.

    But you have another problem:

    Configuring D/DA/DAVIDO/Inline-CPP-0.71.tar.gz with Makefile.PL Warning: prerequisite Inline version 0.78 not found. at Makefile.PL li +ne 123. Warning: prerequisite Inline::C version 0.67 not found. at Makefile.PL + line 123. !!! PREREQUISITES NOT MET !!! at Makefile.PL line 35.

    See that part about needing Inline::C and Inline? How did you get this far with Inline::CPP without those being installed first? I would think that the cpan installers would have handled this recursively for you.


    Dave

Re: Inline::CPP with Visual Studio
by syphilis (Archbishop) on Jun 25, 2015 at 03:05 UTC
    I need to use Visual Studio instead of GCC because I have to link to a closed source 3rd party library that has only been compiled with Visual Studio.

    You should still be able to link to that library using GCC - and that's the path I'd be going down if I had to use Strawberry Perl.
    Assuming this library is a dll (let's call it 'some.dll') then you just need to create a def file for it (unless you already have the def file):
    gendef some.dll
    then create the import library for the dll:
    dlltool --kill-at --input-def some.def --output-lib libsome.a
    Of course, at runtime, 'some.dll' still needs to be found.

    Strawberry ships with both 'dlltool' and 'gendef', afaik.
    And I::CPP should install trivially if you let it use the mingw toolset it expects to use.

    Cheers,
    Rob