ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.46k stars 2.52k forks source link

Compiler can't fetch shared library with version on it ! ( libfoo.so.x.y ) #18465

Open bilaliscarioth opened 9 months ago

bilaliscarioth commented 9 months ago

Zig Version

0.12.0-dev.2040+9a1608509

Steps to Reproduce and Observed Output

Hello Zig Developers !

I tried to follow the issues i caught every time on OpenBSD 7.3 (-current) when we use linkSystemLibrary("foo"). Compiler only check every dir with where file ended as libfoo.so but actually not... Shared library (in most of time) end by a major and a minor version. Which render to something like that libfoo.so.X.Y (as in title).

So we caught the famous:

error: unable to find Dynamic system library 'glib-2.0' using strategy 'paths_first'. searched paths:
  /usr/local/lib/libglib-2.0.so
  /usr/local/lib/libglib-2.0.a
  /usr/X11R6/lib/libglib-2.0.so
  /usr/X11R6/lib/libglib-2.0.a
  /usr/local/lib64/libglib-2.0.so
  /usr/local/lib64/libglib-2.0.a
  /usr/local/lib/libglib-2.0.so
  /usr/local/lib/libglib-2.0.a
  /usr/lib/x86_64-openbsd-gnu/libglib-2.0.so
  /usr/lib/x86_64-openbsd-gnu/libglib-2.0.a
  /lib64/libglib-2.0.so
  /lib64/libglib-2.0.a
  /lib/libglib-2.0.so
  /lib/libglib-2.0.a
  /usr/lib64/libglib-2.0.so
  /usr/lib64/libglib-2.0.a
  /usr/lib/libglib-2.0.so
  /usr/lib/libglib-2.0.a
  /lib/x86_64-openbsd-gnu/libglib-2.0.so
  /lib/x86_64-openbsd-gnu/libglib-2.0.a

Only solution is to use addObjectFile for every shared library used/called by the project or by dependencies. put the absolute file.

the only thing i know it that's probably come from at src/main.zig 3836. but no further. i'll investigate ^^

(edit i find it it's at src/link/Elf.zig at line 2077 (sorry) )

Expected Output

Building without specified the absolute path to shared library

matu3ba commented 9 months ago

Does pkg-config (or the zig usage in the build system) not work for you use case? Why?

bilaliscarioth commented 9 months ago

No.. it's not the pkg-config because it give the correct flags

iscarioth$ pkg-config --cflags --libs glib-2.0
-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -L/usr/local/lib -lglib-2.0 -lintl -lpcre2-8

it's more the zig usage in the build system which is not specific to OpenBSD, i just remember LLD was patched for matching versioned shared library ( https://github.com/openbsd/ports/blob/master/devel/llvm/17/patches/patch-lld_ELF_DriverUtils_cpp )

at src/link/Elf.zig, he only check up the (somewhere in lib dir)`/libglib-2.0.so ( only) ( src/main.zig on accesLibPath)

nektro commented 9 months ago

distros/packages are supposed to symlink libfoo.so to libfoo.so.X etc