Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: A Practical Guide to Compiling C based Modules under ActiveState using Microsoft C++

by PodMaster (Abbot)
on Apr 11, 2003 at 06:13 UTC ( #249818=note: print w/replies, xml ) Need Help??

in reply to A Practical Guide to Compiling C based Modules under ActiveState using Microsoft C++

If you wish to avoid modifying the registry, simply run vcvars32.bat which will set up the appropriate environment variables (modify PATH, add LIB and INCLUDE) before attempting to nmake. vcvars32.bat is specific to MSVS6, but i'm sure MSVS .NET has a similary named batch file which will setup the environment. It's located right next to CL.exe.

I'd really like to stress the importance of reading the README/INSTALL that come with modules. They'll often have common problems( and usually their solutions) others have had trying to compile said extension on win32.

I'd also like to add that you should not be afraid of editing Makefile.PL. Get familiar with ExtUtils::MakeMaker. Most of the time you can get away with modifying your INCLUDE/LIBS environment variables, but not all Makefile.PL's are created equal, and some are written quite poorly (in a non-portable fashion, for no apparent reason -- for example, WriteMakefile is passed 'OBJECT' => '$(O_FILES) '." Foo.o Bar.o Baz.o " which won't fly on windows. The right way to write it would've been as "Foo$Config{obj_ext} Bar$Config{obj_ext} Baz$Config{obj_ext}").

Another common portability issue is #include <uninstd.h>. Lots of extensions include it, but windows has no such beast, and it belongs in an #ifndef. Simply comment it out, and there'll be a good chance the extension will compile.

Also, if a required library will not build on windows, all hope is not lost. You can always get MinGW (aka cygwin), compile the required library, and link with it.

Read How can an MSVC program call a MinGW DLL, and vice versa? on how to do it.

I recently did that with Math::GMP (it's up on my repository), cause it's a requirement for Net::SSH::Perl. If you can live with running GMP via cygwin, you can have Math::GMP on windows.

It is also important to make sure when compiling libraries required for a module to work, like in the case of pure-db, that your compiler options match those of your perl binary. CL /? will reveal the following possible options

-LINKING- /MD link with MSVCRT.LIB /MDd link with MSVCRTD.LIB de +bug lib /ML link with LIBC.LIB /MLd link with LIBCD.LIB debu +g lib /MT link with LIBCMT.LIB /MTd link with LIBCMTD.LIB de +bug lib /LD Create .DLL /F<num> set stack size /LDd Create .DLL debug libary /link [linker options and lib +raries]
What you want is what your perl has
So you'd wanna make sure the -MD option is present. A tell-tale sign that the library you're trying to link to was not compiled with the -MD option is an "unresolved external symbol _pctype".

If you're faced with an error, google it, check, check (the mailing list archives as well) because chances are, somebody has already encountered it and there is a workaround available, and if there isn't, simply report it to the author, cause he'll usually be able to help you.

update: If you get unresolved external symbol _snprintf, you'll need (this is not like the _pctype issue):

#ifdef WIN32 #define snprintf _snprintf #endif

MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
** The Third rule of perl club is a statement of fact: pod is sexy.

  • Comment on Re: A Practical Guide to Compiling C based Modules under ActiveState using Microsoft C++
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: A Practical Guide to Compiling C based Modules under ActiveState using Microsoft C++
by Anonymous Monk on Apr 17, 2007 at 20:05 UTC
    Hi, I'm building a Perl extension (dll in Windows XP) using ExtUtils::MakeMaker. This dll needs to link with other libraries that were built in static mode (-MTd). My perl configuration states dynamic libraries (-MD) which causes MakeMaker to pull a dynamic C library (msvcrtd.dll). The other libraries are using the static C library (libcmtd.lib) These dynamic and static C libraries collide giving link errors. Is there a way to force perl to compile with (-MTd) albeit its configuration flags? Thanks, Avner Moshkovitz Research Analyst MacDonald Dettwiler Direct: (604) 231-2487 13800 Commerce Parkway Fax: (604) 278-2117 Richmond, B.C. Canada V6V 2J3 Email: www:

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://249818]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-12-03 08:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found