Skip to content

Commit

Permalink
correctly pass linker options to MSVC
Browse files Browse the repository at this point in the history
Previously running found.t in debug mode would see results like:

C:\Users\tony\dev\devel-checklib\git\devel-checklib>perl -Mblib t\found.t
1..8
ok 1 - lib => 'msvcrt'
W3 -Od -MD -Zi -DDEBUGGING -DWIN32 -D_CONSOLE -DNO_STRICT -D_CRT_SECURE_NO_DEPRE
CATE -D_CRT_NONSTDC_NO_DEPRECATE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT
 -DPERL_IMPLICIT_SYS -DUSE_PERLIO -nologo -nodefaultlib -debug -libpath:"c:\perl
-5.14.1\lib\CORE" -machine:x86 "/manifestdependency:type='Win32' name='Microsoft
.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyT
oken='6595b64144ccf1df' language='*'" assertlib2s91hAMm.c msvcrt.lib /Feassertli
bJY5x26JC.exe /link
cl : Command line warning D9002 : ignoring unknown option '-nodefaultlib'
cl : Command line warning D9002 : ignoring unknown option '-debug'
cl : Command line warning D9002 : ignoring unknown option '-libpath:c:\perl-5.14
.1\lib\CORE'
cl : Command line warning D9002 : ignoring unknown option '-machine:x86'
cl : Command line warning D9002 : ignoring unknown option '/manifestdependency:t
ype='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processor
Architecture='*' publicKeyToken='6595b64144ccf1df' language='*''
assertlib2s91hAMm.c
ok 2 - ... and check_lib is true
ok 3 - lib => 'kernel32'
W3 -Od -MD -Zi -DDEBUGGING -DWIN32 -D_CONSOLE -DNO_STRICT -D_CRT_SECURE_NO_DEPRE
CATE -D_CRT_NONSTDC_NO_DEPRECATE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT
 -DPERL_IMPLICIT_SYS -DUSE_PERLIO -nologo -nodefaultlib -debug -libpath:"c:\perl
-5.14.1\lib\CORE" -machine:x86 "/manifestdependency:type='Win32' name='Microsoft
.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyT
oken='6595b64144ccf1df' language='*'" assertlibIVQZIq2L.c kernel32.lib /Feassert
libJRvNb0Xb.exe /link
cl : Command line warning D9002 : ignoring unknown option '-nodefaultlib'
cl : Command line warning D9002 : ignoring unknown option '-debug'
cl : Command line warning D9002 : ignoring unknown option '-libpath:c:\perl-5.14
.1\lib\CORE'
cl : Command line warning D9002 : ignoring unknown option '-machine:x86'
cl : Command line warning D9002 : ignoring unknown option '/manifestdependency:t
ype='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processor
Architecture='*' publicKeyToken='6595b64144ccf1df' language='*''
assertlibIVQZIq2L.c
ok 4 - ... and check_lib is true

with the change:

C:\Users\tony\dev\devel-checklib\git\devel-checklib>perl -Mblib t\found.t
1..8
ok 1 - lib => 'msvcrt'
W3 -Od -MD -Zi -DDEBUGGING -DWIN32 -D_CONSOLE -DNO_STRICT -D_CRT_SECURE_NO_DEPRE
CATE -D_CRT_NONSTDC_NO_DEPRECATE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT
 -DPERL_IMPLICIT_SYS -DUSE_PERLIO assertlibi36Qev0i.c msvcrt.lib /FeassertlibP5S
ac4Lk.exe /link -nologo -nodefaultlib -debug -libpath:"c:\perl-5.14.1\lib\CORE"
-machine:x86 "/manifestdependency:type='Win32' name='Microsoft.Windows.Common-Co
ntrols' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144cc
f1df' language='*'" oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.l
ib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib
 msvcrt.lib
assertlibi36Qev0i.c
ok 2 - ... and check_lib is true
ok 3 - lib => 'kernel32'
W3 -Od -MD -Zi -DDEBUGGING -DWIN32 -D_CONSOLE -DNO_STRICT -D_CRT_SECURE_NO_DEPRE
CATE -D_CRT_NONSTDC_NO_DEPRECATE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT
 -DPERL_IMPLICIT_SYS -DUSE_PERLIO assertlibPEMVsg9l.c kernel32.lib /FeassertlibN
LOJ8CLr.exe /link -nologo -nodefaultlib -debug -libpath:"c:\perl-5.14.1\lib\CORE
" -machine:x86 "/manifestdependency:type='Win32' name='Microsoft.Windows.Common-
Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144
ccf1df' language='*'" oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.li
b comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid
.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.l
ib msvcrt.lib
assertlibPEMVsg9l.c
ok 4 - ... and check_lib is true

The libraries are needed since -nodefaultlib skips linking the C
runtime, and $Config{perllibs} includes the C runtime.
  • Loading branch information
tonycoz committed Oct 22, 2011
1 parent bf718a1 commit 74a1a8b
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions lib/Devel/CheckLib.pm
Expand Up @@ -213,7 +213,7 @@ sub assert_lib {
}
}

my @cc = _findcc();
my ($cc, $ld) = _findcc();
my @missing;
my @wrongresult;
my @use_headers;
Expand All @@ -235,21 +235,25 @@ sub assert_lib {
if ( $Config{cc} eq 'cl' ) { # Microsoft compiler
require Win32;
@sys_cmd = (
@cc,
@$cc,
$cfile,
"/Fe$exefile",
(map { '/I'.Win32::GetShortPathName($_) } @incpaths)
(map { '/I'.Win32::GetShortPathName($_) } @incpaths),
"/link",
@$ld
);
} elsif($Config{cc} =~ /bcc32(\.exe)?/) { # Borland
@sys_cmd = (
@cc,
@$cc,
@$ld,
(map { "-I$_" } @incpaths),
"-o$exefile",
$cfile
);
} else { # Unix-ish: gcc, Sun, AIX (gcc, cc), ...
@sys_cmd = (
@cc,
@$cc,
@$ld,
$cfile,
(map { "-I$_" } @incpaths),
"-o", "$exefile"
Expand Down Expand Up @@ -282,18 +286,20 @@ sub assert_lib {
} @libpaths;
# this is horribly sensitive to the order of arguments
@sys_cmd = (
@cc,
@$cc,
$cfile,
"${lib}.lib",
"/Fe$exefile",
(map { '/I'.Win32::GetShortPathName($_) } @incpaths),
"/link",
@$ld,
(map {'/libpath:'.Win32::GetShortPathName($_)} @libpaths),
);
} elsif($Config{cc} eq 'CC/DECC') { # VMS
} elsif($Config{cc} =~ /bcc32(\.exe)?/) { # Borland
@sys_cmd = (
@cc,
@$cc,
@$ld,
"-o$exefile",
"-l$lib",
(map { "-I$_" } @incpaths),
Expand All @@ -302,7 +308,8 @@ sub assert_lib {
} else { # Unix-ish
# gcc, Sun, AIX (gcc, cc)
@sys_cmd = (
@cc,
@$cc,
@$ld,
$cfile,
"-o", "$exefile",
"-l$lib",
Expand Down Expand Up @@ -346,16 +353,22 @@ sub _cleanup_exe {
return
}

# return ($cc, $ld)
# where $cc is an array ref of compiler name, compiler flags
# where $ld is an array ref of linker flags
sub _findcc {
# Need to use $keep=1 to work with MSWin32 backslashes and quotes
my @Config_ccflags_ldflags = @Config{qw(ccflags ldflags)}; # use copy so ASPerl will compile
my @flags = grep { length } map { quotewords('\s+', 1, $_ || ()) } @Config_ccflags_ldflags;
my $Config_ccflags = $Config{ccflags}; # use copy so ASPerl will compile
my @Config_ldflags = @Config{qw(ldflags perllibs)};
my @ccflags = grep { length } quotewords('\s+', 1, $Config_ccflags);
my @ldflags = grep { length } quotewords('\s+', 1, @Config_ldflags);
my @paths = split(/$Config{path_sep}/, $ENV{PATH});
my @cc = split(/\s+/, $Config{cc});
return (@cc, @flags) if -x $cc[0];
return ( [ @cc, @ccflags ], \@ldflags ) if -x $cc[0];
foreach my $path (@paths) {
my $compiler = File::Spec->catfile($path, $cc[0]) . $Config{_exe};
return ($compiler, @cc[1 .. $#cc], @flags) if -x $compiler;
return ([ $compiler, @cc[1 .. $#cc], @ccflags ], \@ldflags)
if -x $compiler;
}
die("Couldn't find your C compiler\n");
}
Expand Down

0 comments on commit 74a1a8b

Please sign in to comment.