Help with OpenCFU build

I am trying to build a project that builds on top of opencv. The project is called OpenCFU: GitHub - qgeissmann/OpenCFU: An easy-to-use C++ application to count bacterial colonies (i.e. CFU). · GitHub

I have two basic scripts so far (TBH these came from claude 4.6):

default.nix

let pkgs = import <nixpkgs> {};
in pkgs.callPackage ./opencfu.nix {}

and then the build script itself opencuf.nix:

{ lib
, stdenv
, fetchFromGitHub
, autoreconfHook
, pkg-config
, opencv4
, gtkmm3
, gtk3
}:

stdenv.mkDerivation rec {
  pname = "opencfu";
  version = "4.0.0";

  src = fetchFromGitHub {
    owner = "qgeissmann";
    repo  = "OpenCFU";
    rev   = "4.0.0";
    hash = "sha256-u2u0cGanCbtPJNkrEvQGlOUEvRNoO/tZTL0zHFUUexk=";
  };
  PKG_CONFIG_PATH = "${opencv4}/lib/pkgconfig";
  nativeBuildInputs = [
    autoreconfHook
    pkg-config
    opencv4
  ];

  buildInputs = [
    opencv4
    gtkmm3
    gtk3
  ];

  meta = with lib; {
    description = "Count bacterial colonies (CFU) in agar-plate images";
    homepage    = "https://github.com/qgeissmann/OpenCFU";
    license     = licenses.gpl3Only;
    platforms   = platforms.linux;
    maintainers = [];
  };
}

The error I am getting when doing: nix-build --no-out-link is that opencv is not found. Not entirely sure I’m doing this right, but the over all flow makes sense. Any suggestions for building opencfu? this is on linux on nixos itself not mac osx (claude claims opencfu has a mac osx build artifact in it).

This was fixed upstream in Update configure.ac for opencv 4 on ubuntu 20 · qgeissmann/OpenCFU@7fb7c6d · GitHub, unfortunately the project hasn’t created a release since.

You also don’t need to set PKG_CONFIG_PATH as this is done automatically when you include pkg-config.

ok so if I take the current main it should get rid of that error then? Is there a patch I can include for this? Thanks for suggestion.

tried this:

  preConfigure = ''
    substituteInPlace configure.ac \
      --replace "opencv >= 3.0.0" "opencv4 >= 3.0.0"
  '';

Additionally switched to master and no change.

error: builder for '/nix/store/gp44k7khpr68fxsjjzpaywnh4znj4lxg-opencfu-4.0.0.drv' failed with exit code 1;
       last 25 log lines:
       > checking for gawk... gawk
       > checking whether make sets $(MAKE)... yes
       > checking whether make supports nested variables... yes
       > checking whether the C++ compiler works... yes
       > checking for C++ compiler default output file name... a.out
       > checking for suffix of executables...
       > checking whether we are cross compiling... no
       > checking for suffix of object files... o
       > checking whether the compiler supports GNU C++... yes
       > checking whether g++ accepts -g... yes
       > checking for g++ option to enable C++11 features... none needed
       > checking whether make supports the include directive... yes (GNU style)
       > checking dependency style of g++... none
       > ./configure: line 4265: gcc-mp-4.8: command not found
       > checking whether g++ supports C++11 features by default... yes
       > checking for gcc... gcc
       > checking whether the compiler supports GNU C... yes
       > checking whether gcc accepts -g... yes
       > checking for gcc option to enable C11 features... none needed
       > checking whether gcc understands -c and -o together... yes
       > checking dependency style of gcc... none
       > checking for gcc option to support OpenMP... -fopenmp
       > checking pkg-config is at least version 0.9.0... yes
       > checking for OPENCV... no
       > configure: error: OpenCV not found. Have you installed the library (devel version)
       For full logs, run 'nix log /nix/store/gp44k7khpr68fxsjjzpaywnh4znj4lxg-opencfu-4.0.0.drv'.

i played about with this derivation locally, but didn’t figure out what’s going wrong. adding some extra logging shows opencv4 is definitely added to the PKG_CONFIG_PATH, and pkg-config can see it, but configure still fails. Someone more familiar with configure.ac esoterics is needed here

You need to change it from preConfigure (after configure has been generated) to preAutoreconf (before configure has been generated).

1 Like