Skip to content

Commit

Permalink
Make sure linking works even when CC is set to C++ compiler
Browse files Browse the repository at this point in the history
This can happen when using a module such as `ExtUtils::CppGuess` which
sets `CC` and `CCFLAGS` to C++ compiler specific values. When combined
with `Module::Build` which calls `ExtUtils::CBuilder::Base::have_compiler`
with those values, the branch that checks for a C compiler is run with
those C++ compiler specific values which causes a linker error.
  • Loading branch information
zmughal committed Sep 15, 2023
1 parent 4fe0a85 commit e5816fd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Base.pm
Expand Up @@ -205,7 +205,13 @@ sub have_compiler {
print $FH q<namespace Bogus { extern "C" int boot_compilet() { return 1; } };> . "\n";
}
else {
print $FH "int boot_compilet(void) { return 1; }\n";
# Use extern "C" if "cc" was set to a C++ compiler.
print $FH <<EOF;
#ifdef __cplusplus
extern "C"
#endif
int boot_compilet(void) { return 1; }
EOF
}
close $FH;

Expand Down

0 comments on commit e5816fd

Please sign in to comment.