-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use rpath when compiling on macOS. #35
Conversation
This fixes issue #337 for DBD::mysql. When compiling on macOS the rpath must be explicitly set with linker option -Wl,-rpath or else the dynamic loader will refuse to load the library. Note that many workarounds exists like setting DYLD_LIBRARY_PATH or using install_name_tool. However, setting rpath for the generated executable is to be preferred and is the simplest solution.
p5-Devel-CheckLib/lib/Devel/CheckLib.pm Line 416 in 593ac19
So if this code does not work for your platform, you should extend this code instead of adding ad-hoc hacks on other places. I do not remember exact differences between |
I see... But in this case Devel::CheckLib should not set |
Ok! I would suggest to not set additional ENV variables (or options) which does not work. It could confuse people in future if there would be another different problem. So what about following change? I tried to simplify it to use current coding style... --- CheckLib.pm 2021-11-03 18:27:05.532843767 +0100
+++ CheckLib.pm 2021-11-03 18:33:43.065846954 +0100
@@ -407,13 +407,14 @@ sub assert_lib {
(map { "-I$_" } @incpaths),
$cfile,
(map { "-L$_" } @libpaths),
+ ($^O eq 'darwin' ? (map { "-Wl,-rpath,$_" } @libpaths) : ()),
"-l$lib",
@$ld,
"-o", "$exefile",
);
}
warn "# @sys_cmd\n" if $args{debug};
- local $ENV{LD_RUN_PATH} = join(":", grep $_, @libpaths, $ENV{LD_RUN_PATH}) unless $^O eq 'MSWin32';
+ local $ENV{LD_RUN_PATH} = join(":", grep $_, @libpaths, $ENV{LD_RUN_PATH}) unless $^O eq 'MSWin32' or $^O eq 'darwin';
local $ENV{PATH} = join(";", @libpaths).";".$ENV{PATH} if $^O eq 'MSWin32';
my $rv = $args{debug} ? system(@sys_cmd) : _quiet_system(@sys_cmd);
if ($rv != 0 || ! -f $exefile) { |
LD_RUN_PATH is not supported by the macOS system linker, so we do not set LD_RUN_PATH environment variable on macOS, instead we use linker option -rpath which does the same thing.
@pali It looks good to me. I have updated this PR with the change you suggested. I tested it for both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks for testing!
I've given you co-maint, but do please give @mattn a chance to respond before forking and making a release :-) |
Also added @zmughal as co-maint |
This fixes issue #337 for
DBD::mysql
. When compiling on macOS the rpath must be explicitly set with linker option-Wl,-rpath
or else the dynamic loader will refuse to load the library. Note that many workarounds exists like settingDYLD_LIBRARY_PATH
or usinginstall_name_tool
. However, setting rpath for the generated executable is to be preferred and is the simplest solution.