anduril / jetpack-nixos

NixOS module for NVIDIA Jetson devices
MIT License
166 stars 70 forks source link

OpenCV with CUDA fails to build with linker errors #109

Open hacker1024 opened 1 year ago

hacker1024 commented 1 year ago

I am attempting to configure OpenCV with CUDA for an Orin NX like so:

{ pkgs ? import <nixpkgs> { } }:

let
  jetpack = pkgs.callPackage ./path/to/jetpack { };
in
pkgs.appendOverlays [
  (self: super: {
    cudaPackages = jetpack.cudaPackages // {
      inherit (jetpack) cudaVersion;
      # https://github.com/anduril/jetpack-nixos/blob/ddaff1bfceafb93ea67cb4ef953ba8eff5cf942b/cuda-packages.nix#L35
      inherit (pkgs.cudaPackages_11_3) backendStdenv;
      cudaFlags = self.cudaPackages_11_4.cudaFlags.override {
        config.cudaCapabilities = [ "8.6" ];
        config.cudaForwardCompat = false;
      };
    }

    opencv4 = (super.opencv4.override ({
      enableGtk3 = true;
      cudaPackages = self.cudaPackages;
      enableCuda = true;
      enableCudnn = true;
    };
  })
];

This, however, is failing with glibc-related liker errors like the following.

opencv> /nix/store/6f700gwk2wvy8rp9licldryx0hbvhapn-binutils-2.40/bin/ld: /nix/store/sn546k2nnp9fd4fcfhdp1ni0ql8yclkn-openexr-2.5.8/lib/libIlmImf-2_5.so.26: undefined reference to `std::__throw_bad_array_new_length()@GLIBCXX_3.4.29'
opencv> collect2: error: ld returned 1 exit status
opencv> make[2]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:103: bin/opencv_annotation] Error 1
opencv> make[1]: *** [CMakeFiles/Makefile2:8698: apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
opencv> make[1]: *** Waiting for unfinished jobs....

Disabling OpenEXR or the OpenCV apps module only postpones the error. Whatever the configuration, the same linker error always shows up at some point.

How can OpenCV be built? If this is a configuration issue, I think it would be useful to add a version of OpenCV with the relevant CUDA overrides to this repository's package set.

hacker1024 commented 1 year ago

https://github.com/NixOS/nixpkgs/issues/220341 may have something to do with this.