Skip to content

foreign import shared system library does not work #2857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thechampagne opened this issue Oct 9, 2023 · 4 comments
Open

foreign import shared system library does not work #2857

thechampagne opened this issue Oct 9, 2023 · 4 comments
Labels

Comments

@thechampagne
Copy link

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"
@flysand7
Copy link
Contributor

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.

image

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.

image

@flysand7
Copy link
Contributor

The other hypothesis is that it's probably a typo: Here's me trying to link to glfw3 using gcc

image

@flysand7
Copy link
Contributor

flysand7 commented Oct 16, 2023

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

@orangebowlerhat
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants