Odin
Odin copied to clipboard
foreign import shared system library does not work
Linux Mint 21
odin version dev-2023-10:cffa035c
It will search in path where it runs instead of system path.
foreign import lib "system:libname.so" // behaves like 'foreign import lib "libname.so"'
However importing static library works.
foreign import lib "system:libname.a"
Confirmed. I can pin the bug down to the fact that shared object detection is done by checking the filename suffix.
// src/linker.cpp:385
if (string_ends_with(lib, str_lit(".a")) || string_ends_with(lib, str_lit(".o"))) {
lib_str = gb_string_append_fmt(lib_str, " -l:\"%.*s\" ", LIT(lib));
} else if (string_ends_with(lib, str_lit(".so"))) {
lib_str = gb_string_append_fmt(lib_str, " -l:\"%s/%.*s\" ", cwd, LIT(lib));
} else {
lib_str = gb_string_append_fmt(lib_str, " -l%.*s ", LIT(lib));
}
I've inserted some printfs into this code, recompiled the Odin compiler and built the following file:
package main
import "core:fmt"
@require foreign import lib "system:raylib.so"
main :: proc() {
fmt.printf("Hellope!\n")
}
The result's execution depends on the presence of raylib in the current directory despite the system import being used. In both cases the import is detected as SHARED LIB
and uses codepath that expects the user to put the shared object into current working directory.
Also, I'll put it here, because it's somewhat related: it doesn't search the CWD for the library at runtime, because CWD isn't specified in rpath
.
The other hypothesis is that it's probably a typo: Here's me trying to link to glfw3 using gcc
UPD: Seems like system:
does absolutely nothing and has no special semantics...
It's only used on linux to differentiate between something like -lpthread
and -l:mylib.so
This issue entirely stops me from using the language. I want to use a system library on linux and there is apparently no way to do so. I quite literally cannot write the program I intended to write in odin.