Skip to content
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

Odinlang project fails to build, reason: ld cannot find <static libraries> no such file or directory. #338972

Open
Vonixxx opened this issue Sep 2, 2024 · 4 comments · May be fixed by odin-lang/Odin#4619
Labels
0.kind: bug Something is broken

Comments

@Vonixxx
Copy link
Contributor

Vonixxx commented Sep 2, 2024

Describe the bug

When I try to build my Odinlang project using nix-build -A package, I get the following errors:

/nix/store/qsx2xqqm0lp6d8hi86r4y0rz5v9m62wn-binutils-2.42/bin/ld: cannot find -l:/nix/store/5kqscq1vk49zpjw5h3gqmnlzb87wfvli-odin-0-unstable-2024-08-05/share/vendor/raylib/linux/libraygui.a: No such file or directory

/nix/store/qsx2xqqm0lp6d8hi86r4y0rz5v9m62wn-binutils-2.42/bin/ld: cannot find -l:/nix/store/5kqscq1vk49zpjw5h3gqmnlzb87wfvli-odin-0-unstable-2024-08-05/share/vendor/raylib/linux/libraylib.a: No such file or directory

When I check the respective locations, I can see the static library files are where they are supposed to be. So then why does ld state they are not present?

Steps To Reproduce

  1. Clone nixpkgs.
  2. Add my package.
  3. nix-build -A search.
Package derivation
{
  lib,
  odin,
  xorg,
  libGL,
  stdenv,
  fetchFromGitHub,
}:
 
stdenv.mkDerivation (finalAttrs: {
  version = "V1.0";
  pname = "search";
 
  src = fetchFromGitHub {
    repo = "Search";
    owner = "Vonixxx";
    rev = finalAttrs.version;
    hash = "sha256-VIxdF3+/3CjPw/L/e44oEDvZ8uPUpXcq8RPo4Eidn7M=";
  };
 
  buildInputs = [
    odin
    libGL
    xorg.libX11
  ];
 
  buildPhase = ''
    runHook preBuild
 
    odin build Src -file -out:search
 
    runHook postBuild
  '';
 
  installPhase = ''
    runHook preInstall
 
    install -Dm755 search $out/bin
 
    runHook postInstall
  '';
 
  meta = {
    inherit (odin.meta) platforms;
    description = "A Simple Search Utility";
    homepage = "https://github.com/Vonixxx/Search";
    license = lib.licenses.gpl3;
    maintainers = with lib.maintainers; [ vonixxx ];
    mainProgram = "search";
  };
})

Expected behavior

The package should build. I also have a nix develop flake, which works and lets me compile the project as well as execute it.

Nix develop flake
{
 inputs = {
   nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
 };
 
 outputs = {
   nixpkgs
 , ...
 }:
 
 let
  inherit (pkgs)
   mkShell;
 
  inherit (pkgs.lib)
   makeLibraryPath;
 
  pkgs = import nixpkgs {
    system = "x86_64-linux";
  };
 in {
   devShells.x86_64-linux.default = mkShell {
     buildInputs = with pkgs; [
       libGL
       odin
       xorg.libX11
     ];
 
     LD_LIBRARY_PATH = with pkgs; "$LD_LIBRARY_PATH:${
        makeLibraryPath [
         libGL
         xorg.libX11
        ]
     }";
   };
 };
}

Additional context

I have tried the following:

  • Use lld instead of ld.
  • Use autoPatchelfHook as suggested on the forum post I made.
  • Manually point to the static library files by using NIX_CFLAGS_COMPILE, i.e. -l${odin}/share/vendor/raylib/linux/libraylib.a and -l${odin}/share/vendor/raylib/linux/libraygui.a.
  • Copied the static library files in my home directory, and manually pointed to them as above.
  • Enabled RAYLIB_SHARED as an option for Odinlang, which makes use of the dynamic library instead of the static ones.
  • Tried makeBinaryWrapper just as ols uses.

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.5.0-valve19, NixOS, 24.11 (Vicuna), 24.11.20240828.71e91c4`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - nixpkgs: `/nix/store/887hpp8a2i99n9jjwcvz6qkhhhqsvzkg-source`

Add a 👍 reaction to issues you find important.

@Vonixxx Vonixxx added the 0.kind: bug Something is broken label Sep 2, 2024
@xakep8
Copy link

xakep8 commented Sep 5, 2024

I would like to work on this issue could you please help me with the file structure?

@Vonixxx
Copy link
Contributor Author

Vonixxx commented Sep 5, 2024

I would link to work on this issue could you please help me with the file structure?

What do you mean?

@Vonixxx
Copy link
Contributor Author

Vonixxx commented Oct 17, 2024

I have not found a solution.

For the time being, I use nix-ld to acquire the needed libraries after which I merge LD_LIBRARY_PATH with NIX_LD_LIBRARY_PATH using environment.sessionVariables.

@spitulax
Copy link
Contributor

This is an issue with the Odin compiler. It cannot link to libraries shipped into the compiler, you have to compile the libraries with Nix, or fetch it from nixpkgs. But currently in nixos-unstable, raylib is still in version 5.0 but the Odin binding from the latest compiler is in version 5.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants