What's the right way to specify compilation and linking with -pthread
(not -lpthread
) in a Makefile.PL?
It's my understanding that gcc ought to be invoked with -pthread
when building against pthreads, as this flag expands to the correct platform-specific flags for both compilation and linking.
I started with:
use Config;
my %mm = ( NAME => 'Local::Example::Pthreaded', ...);
...
if ($Config{ccname} eq 'gcc') {
$mm{DEFINE} = join(' ', '-pthread', $mm{DEFINE}); # ??? in the right place?
$mm{LIBS} = ['-pthread']; # XXX ignored!
}
WriteMakefile(%mm);
However, I'm not sure that the DEFINE usage puts -pthread
in the right place. (User DEFINEs appears at the end of the compilation command.) Moreover, the LIBS argument is ignored because it doesn't look like a typical -l
/-L
linker argument: "Unrecognized argument in LIBS ignored: '-pthread'".