aboutsummaryrefslogtreecommitdiff
path: root/src/linker.cpp
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2024-09-04 22:18:55 +0200
committerLaytan <laytanlaats@hotmail.com>2024-09-04 22:19:46 +0200
commit1a7c1d107a26df00bc6c9379178fccb55569b667 (patch)
tree9876dbdaf25abef23d853622a9dcac2eb6cb4a29 /src/linker.cpp
parent578de0977527a9cef7d1d77fab785363997b7cb6 (diff)
set -rpath to \$ORIGIN and expect libraries next to executable just like Windows
Diffstat (limited to 'src/linker.cpp')
-rw-r--r--src/linker.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/linker.cpp b/src/linker.cpp
index faca28932..25b9cfdc3 100644
--- a/src/linker.cpp
+++ b/src/linker.cpp
@@ -548,14 +548,12 @@ gb_internal i32 linker_stage(LinkerData *gen) {
// available at runtime wherever the executable is run, so we make require those to be
// 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"))) {
+ 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));
- } else if (string_ends_with(lib, str_lit(".so")) || string_contains_string(lib, str_lit(".so."))) {
- // dynamic lib, relative path to executable
- // NOTE(vassvik): it is the user's responsibility to make sure the shared library files are visible
- // at runtime to the executable
- lib_str = gb_string_append_fmt(lib_str, " -l:\"%s/%.*s\" ", cwd, 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));
@@ -643,6 +641,10 @@ gb_internal i32 linker_stage(LinkerData *gen) {
}
}
+ // Set the rpath to the $ORIGIN (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.no_crt) {
platform_lib_str = gb_string_appendc(platform_lib_str, "-lm ");
if (build_context.metrics.os == TargetOs_darwin) {