support the rpath changes on macos

This commit is contained in:
Laytan Laats
2024-09-04 23:45:30 +02:00
parent 0aa971207b
commit 6778598bc6
2 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -549,11 +549,7 @@ gb_internal i32 linker_stage(LinkerData *gen) {
// local to the executable (unless the system collection is used, in which case we search
// the system library paths for the library file).
if (string_ends_with(lib, str_lit(".a")) || string_ends_with(lib, str_lit(".o")) || string_ends_with(lib, str_lit(".so")) || string_contains_string(lib, str_lit(".so."))) {
// static libs and object files, absolute full path relative to the file in which the lib was imported from
lib_str = gb_string_append_fmt(lib_str, " -l:\"%.*s\" ", LIT(lib));
// NOTE(laytan): If .so, I think we can check for the existence of "$OUT_DIRECTORY/$lib" here and print an error telling the user to copy over the file, or we can even do the copy for them?
} else {
// dynamic or static system lib, just link regularly searching system library paths
lib_str = gb_string_append_fmt(lib_str, " -l%.*s ", LIT(lib));
@@ -642,9 +638,13 @@ gb_internal i32 linker_stage(LinkerData *gen) {
}
if (!build_context.no_rpath) {
// Set the rpath to the $ORIGIN (the path of the executable),
// Set the rpath to the $ORIGIN/@loader_path (the path of the executable),
// so that dynamic libraries are looked for at that path.
gb_string_appendc(link_settings, "-Wl,-rpath,\\$ORIGIN ");
if (build_context.metrics.os == TargetOs_darwin) {
link_settings = gb_string_appendc(link_settings, "-Wl,-rpath,@loader_path ");
} else {
link_settings = gb_string_appendc(link_settings, "-Wl,-rpath,\\$ORIGIN ");
}
}
if (!build_context.no_crt) {