aboutsummaryrefslogtreecommitdiff
path: root/src/linker.cpp
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-18 10:51:08 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2025-05-18 11:11:02 -0400
commit591118c68804bf89b9ee3d371b14c54133f4655c (patch)
treeae2277c45ce9f0d9ec73302af292527e971c017c /src/linker.cpp
parent558eca8c7a526f3b213073d5238f73c63c7bb5ba (diff)
Use `--sysroot` instead of `-Wl,-syslibroot` on Darwin
This keeps the linker from using the wrong SDK and mirrors how we build the Odin compiler itself in `build_odin.sh`.
Diffstat (limited to 'src/linker.cpp')
-rw-r--r--src/linker.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/linker.cpp b/src/linker.cpp
index ec165ef7d..087bb49f1 100644
--- a/src/linker.cpp
+++ b/src/linker.cpp
@@ -769,7 +769,17 @@ try_cross_linking:;
gbString platform_lib_str = gb_string_make(heap_allocator(), "");
defer (gb_string_free(platform_lib_str));
if (build_context.metrics.os == TargetOs_darwin) {
- platform_lib_str = gb_string_appendc(platform_lib_str, "-Wl,-syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -L/usr/local/lib ");
+ // Get the MacOSX SDK path.
+ gbString darwin_sdk_path = gb_string_make(temporary_allocator(), "");
+ if (!system_exec_command_line_app_output("xcrun --sdk macosx --show-sdk-path", &darwin_sdk_path)) {
+ darwin_sdk_path = gb_string_set(darwin_sdk_path, "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk");
+ } else {
+ // Trim the trailing newline.
+ darwin_sdk_path = gb_string_trim_space(darwin_sdk_path);
+ }
+ platform_lib_str = gb_string_append_fmt(platform_lib_str, "--sysroot %s ", darwin_sdk_path);
+
+ platform_lib_str = gb_string_appendc(platform_lib_str, "-L/usr/local/lib ");
// Homebrew's default library path, checking if it exists to avoid linking warnings.
if (gb_file_exists("/opt/homebrew/lib")) {