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

opencv 4.7.0 in nixpkgs master has link errors #214124

Closed
tfc opened this issue Feb 2, 2023 · 6 comments · Fixed by #213185
Closed

opencv 4.7.0 in nixpkgs master has link errors #214124

tfc opened this issue Feb 2, 2023 · 6 comments · Fixed by #213185
Assignees
Labels
0.kind: bug Something is broken

Comments

@tfc
Copy link
Contributor

tfc commented Feb 2, 2023

Describe the bug

Hi, I created a minimal demonstrator for my problem:
https://github.com/tfc/whiteboard-opencv/tree/without-aruco (not main branch but without-aruco, to also build with nixos 22.11)

This minimal C++ app includes and links against opencv4.

Building this flake using nix build works just fine and the resulting app works.
Running nix develop and then doing mkdir build && cd build && cmake .. && make results in link errors:

... many others omitted ...
nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/g8lrv5d3ixb2gmyhl14wkb6jl7wnqadc-opencv-4.7.0/lib/libopencv_core.so.4.7.0: undefined reference to `omp_get_max_threads@OMP_1.0'
/nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/g8lrv5d3ixb2gmyhl14wkb6jl7wnqadc-opencv-4.7.0/lib/libopencv_videoio.so.4.7.0: undefined reference to `gst_caps_set_simple'
/nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/g8lrv5d3ixb2gmyhl14wkb6jl7wnqadc-opencv-4.7.0/lib/libopencv_core.so.4.7.0: undefined reference to `clCreateCommandQueue@OPENCL_1.0'
/nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/g8lrv5d3ixb2gmyhl14wkb6jl7wnqadc-opencv-4.7.0/lib/libopencv_dnn.so.4.7.0: undefined reference to `google::protobuf::RepeatedPtrField<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::RemoveLast()'
/nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/g8lrv5d3ixb2gmyhl14wkb6jl7wnqadc-opencv-4.7.0/lib/libopencv_videoio.so.4.7.0: undefined reference to `avcodec_get_context_defaults3@LIBAVCODEC_58'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/DisplayImage.dir/build.make:107: DisplayImage] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

With nixpkgs on 22.11, both nix build and nix develop work.

Steps To Reproduce

Steps to reproduce the behavior:

  1. check out reproducer repo
  2. Run nix build, works
  3. Enter nix shell using nix develop and run: mkdir build && cd build && cmake .. && make, get mentioned error messages
  4. Change flake input to nixpkgs 22.11
  5. Repeat step 1 & 2 and see that they work

Expected behavior

I would expect to not get these linker errors after upgrading to nixpkgs master

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Notify maintainers

@mdaiter @basvandijk

Metadata

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

$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.90, NixOS, 22.11 (Raccoon)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(root): `"home-manager-21.11.tar.gz, nixos-21.11, nixos-unstable"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@tfc tfc added the 0.kind: bug Something is broken label Feb 2, 2023
@gbtb
Copy link
Member

gbtb commented Feb 2, 2023

Hi 👋 Could you try building your flake with nixpkgs from the staging branch ? There are some changes that I've made to this package which are not yet merged into master https://github.com/NixOS/nixpkgs/blob/staging/pkgs/development/libraries/opencv/4.x.nix, maybe it'll help.
Also, I'm not very knowledgeable how c++ linking/compiling works, but from the look of this error messages it seems that dependencies of opencv - such as openmp, gstreamer, opencl, etc are missing from the environment. What if you add them explicitly, probably through opencv4.buildInputs ?
P. S. Maintainers listed for this package seems to be not active anymore (they've never responded me from the last october till today)

@tfc
Copy link
Contributor Author

tfc commented Feb 4, 2023

I just finished bisecting nixpkgs: The commit 8c80bd08b7e39229947d55104d1871f5066437d9 breaks it for me. @trofi do you have any insights on that?

I am trying staging now following your suggestion and will report back.

@tfc
Copy link
Contributor Author

tfc commented Feb 4, 2023

Also, I'm not very knowledgeable how c++ linking/compiling works, but from the look of this error messages it seems that dependencies of opencv - such as openmp, gstreamer, opencl, etc are missing from the environment. What if you add them explicitly, probably through opencv4.buildInputs?

With dynamic linking, this should never be necessary. If it works with explicit linking against these deps, I would still consider this a bug.

@trofi
Copy link
Contributor

trofi commented Feb 4, 2023

I just finished bisecting nixpkgs: The commit 8c80bd08b7e39229947d55104d1871f5066437d9 breaks it for me. @trofi do you have any insights on that?

I am trying staging now following your suggestion and will report back.

Yeah, my apologies for the breakage. That change was reverted for a very similar reason in #213185 and is in staging-next now. Can you try that one instead? That hopefully should not be too many rebuilds on you.

@tfc
Copy link
Contributor Author

tfc commented Feb 4, 2023

Oh yes, thank you for pointing me to that, I try that branch.

@tfc
Copy link
Contributor Author

tfc commented Feb 4, 2023

It's already all in the binary cache, so that was quick. This resolved my problem, thank you!

@trofi trofi linked a pull request Feb 4, 2023 that will close this issue
13 tasks
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.

6 participants