From 3fc8f85c828d9dde9db826fdef8db0744ae674a3 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Tue, 19 Mar 2024 15:22:28 -0400 Subject: Make loadlibLd, filter by architecture if multiple candidates Fixes https://discord.com/channels/956758212152025098/956758650700046366/1202431317971570728 --- lib/c.tcl | 12 +++++++++++- lib/terminal.tcl | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/c.tcl b/lib/c.tcl index 5d995fd5..abc696b9 100644 --- a/lib/c.tcl +++ b/lib/c.tcl @@ -524,9 +524,19 @@ namespace eval c { $loader compile proc loadlib {filename} { if {[loadlibImpl $filename] == "(void*) 0x0"} { - error "Failed to dlopen $filename: [loadlibError]" + error "c loadlib: Failed to dlopen $filename: [loadlibError]" } } + proc loadlibLd {libname} { + set candidates [split [exec /usr/sbin/ldconfig -p | grep $libname] "\n"] + if {[llength $candidates] == 0} { + error "c loadlibLd: Could not find library $libname" + } elseif {[llength $candidates] > 1} { + # Is it greater than 1? if so, filter by arch + set candidates [lsearch -all -inline $candidates *$::tcl_platform(machine)*] + } + loadlib [lindex $candidates 0 end] + } namespace export * namespace ensemble create diff --git a/lib/terminal.tcl b/lib/terminal.tcl index f81847e6..2ab8dd2d 100644 --- a/lib/terminal.tcl +++ b/lib/terminal.tcl @@ -63,7 +63,7 @@ set cc [c create] $cc cflags -I./vendor/libtmt ./vendor/libtmt/tmt.c if {$::tcl_platform(os) ne "Darwin"} { - c loadlib [lindex [exec /usr/sbin/ldconfig -p | grep libutil.so | head -1] end] + c loadlibLd libutil } $cc cflags -lutil -- cgit v1.2.3