Discussion:
[Nix-dev] How to build a Haskell binding to a C++ library (OpenCV) on OS X
Bas van Dijk
2017-06-18 19:47:14 UTC
Permalink
Good evening,

I'm trying to build our Haskell binding to the OpenCV C++ library on OS X.
The following commands should do the job:

git clone https://github.com/LumiGuide/haskell-opencv.git
cd opencv
nix-build

Unfortunately it fails during the configure phase with:

Setup: Cannot find the program 'gcc'.
User-specified path 'g++' does not refer
to an executable and the program is not on the system path.

If I add gcc to the build dependencies of opencv/opencv.nix using:

buildDepends = [ gcc ];

and invoke nix-build again I get a different error:

Setup: Missing dependencies on foreign libraries:
* Missing C libraries: stdc++, opencv_stitching, opencv_superres,
opencv_videostab, opencv_aruco, opencv_bgsegm, opencv_bioinspired,
opencv_ccalib, opencv_dpm, opencv_freetype, opencv_fuzzy,
opencv_line_descriptor, opencv_optflow, opencv_reg, opencv_saliency,
opencv_stereo, opencv_structured_light,
opencv_phase_unwrapping, opencv_rgbd,
opencv_surface_matching, opencv_tracking, opencv_datasets, opencv_text,
opencv_face, opencv_plot, opencv_dnn, opencv_xfeatures2d, opencv_shape,
opencv_video, opencv_ximgproc, opencv_calib3d, opencv_features2d,
opencv_flann, opencv_xobjdetect, opencv_objdetect, opencv_ml,
opencv_xphoto,
opencv_highgui, opencv_videoio, opencv_imgcodecs, opencv_photo,
opencv_imgproc, opencv_core
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the
libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they
are.

Any ideas how to get this working?

Regards,

Bas
Bas van Dijk
2017-06-18 20:22:25 UTC
Permalink
I forgot to mention that the following does work:

git clone https://github.com/LumiGuide/haskell-opencv.git
cd opencv
nix-shell
cabal configure -v
cabal build

In this case cabal is using the g++ from /usr/bin instead of the one from
the nix store since I'm using an impure nix-shell:

Using gcc version 4.2.1 given by user at: /usr/bin/g++

Bas
Post by Bas van Dijk
Good evening,
I'm trying to build our Haskell binding to the OpenCV C++ library on OS X.
git clone https://github.com/LumiGuide/haskell-opencv.git
cd opencv
nix-build
Setup: Cannot find the program 'gcc'.
User-specified path 'g++' does not refer
to an executable and the program is not on the system path.
buildDepends = [ gcc ];
* Missing C libraries: stdc++, opencv_stitching, opencv_superres,
opencv_videostab, opencv_aruco, opencv_bgsegm, opencv_bioinspired,
opencv_ccalib, opencv_dpm, opencv_freetype, opencv_fuzzy,
opencv_line_descriptor, opencv_optflow, opencv_reg, opencv_saliency,
opencv_stereo, opencv_structured_light,
opencv_phase_unwrapping, opencv_rgbd,
opencv_surface_matching, opencv_tracking, opencv_datasets, opencv_text,
opencv_face, opencv_plot, opencv_dnn, opencv_xfeatures2d, opencv_shape,
opencv_video, opencv_ximgproc, opencv_calib3d, opencv_features2d,
opencv_flann, opencv_xobjdetect, opencv_objdetect, opencv_ml,
opencv_xphoto,
opencv_highgui, opencv_videoio, opencv_imgcodecs, opencv_photo,
opencv_imgproc, opencv_core
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the
libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they
are.
Any ideas how to get this working?
Regards,
Bas
Laverne Schrock
2017-06-19 12:23:05 UTC
Permalink
Post by Bas van Dijk
Good evening,
I'm trying to build our Haskell binding to the OpenCV C++ library on
  git clone https://github.com/LumiGuide/haskell-opencv.git
  cd opencv
  nix-build
  Setup: Cannot find the program 'gcc'.   User-specified path 'g++'
does not refer  to an executable and the program is not on the system
path.
If I add gcc to the build dependencies of opencv/opencv.nix using: 
  buildDepends = [ gcc ];
  Setup: Missing dependencies on foreign libraries:  * Missing C
libraries: stdc++, opencv_stitching, opencv_superres, 
opencv_videostab, opencv_aruco, opencv_bgsegm, opencv_bioinspired, 
opencv_ccalib, opencv_dpm, opencv_freetype, opencv_fuzzy, 
opencv_line_descriptor, opencv_optflow, opencv_reg, opencv_saliency, 
opencv_stereo, opencv_structured_light, opencv_phase_unwrapping,
opencv_rgbd,  opencv_surface_matching, opencv_tracking,
opencv_datasets, opencv_text,  opencv_face, opencv_plot, opencv_dnn,
opencv_xfeatures2d, opencv_shape,  opencv_video, opencv_ximgproc,
opencv_calib3d, opencv_features2d,  opencv_flann, opencv_xobjdetect,
opencv_objdetect, opencv_ml, opencv_xphoto,  opencv_highgui,
opencv_videoio, opencv_imgcodecs, opencv_photo,  opencv_imgproc,
opencv_core  This problem can usually be solved by installing the
system packages that  provide these libraries (you may need the "-
dev" versions). If the libraries  are already installed but in a non-
standard location then you can use the  flags --extra-include-dirs=
and --extra-lib-dirs= to specify where they are.
Any ideas how to get this working?
Regards,
Bas
Have you tried adding opencv as a buildInput? Maybe something like:

`buildInputs = [ stdenv opencv3 ] ;`?

But I have no idea what `libraryPkgconfigDepends = [ opencv3 ];` is
supposed to be doing.
Vincent Laporte
2017-06-19 15:00:12 UTC
Permalink
Hi,

Notice that if you replace the two occurrences of ‘g++’ by ‘clang++’ in
the file ‘opencv/Setup.hs’, then ‘nix-build’ succeeds.

This issue might be reported upstream: they apparently need a configure
step to select the correct name of the C++ compiler.

The following patch also appears to make ‘nix-build’ work.

Regards,
--
Vincent.

```
diff --git a/opencv/Setup.hs b/opencv/Setup.hs
index 031daa1..3c92176 100644
--- a/opencv/Setup.hs
+++ b/opencv/Setup.hs
@@ -3,6 +3,6 @@ import System.Environment ( getArgs )

main = do
args <- getArgs
- let args' | "configure" `elem` args = args ++ ["--with-gcc","g++",
"--with-ld","g++"]
+ let args' | "configure" `elem` args = args
| otherwise = args
defaultMainArgs args'
diff --git a/opencv/opencv.nix b/opencv/opencv.nix
index a28674c..80ed995 100644
--- a/opencv/opencv.nix
+++ b/opencv/opencv.nix
@@ -103,8 +103,8 @@ mkDerivation ({
libraryPkgconfigDepends = [ opencv3 ];

configureFlags =
- [ "--with-gcc=g++"
- "--with-ld=g++"
+ [ "--with-gcc=${stdenv.cc}/bin/c++"
+ "--with-ld=${stdenv.cc}/bin/c++"
];

hardeningDisable = [ "bindnow" ];
```
Bas van Dijk
2017-06-19 17:05:36 UTC
Permalink
Thanks Vincent, you are spot on!

I went with the following change:

https://github.com/LumiGuide/haskell-opencv/commit/6b78bc4c431d693b0bc828cc86708882a26f777c

Bas
Hi,
Notice that if you replace the two occurrences of ‘g++’ by ‘clang++’ in
the file ‘opencv/Setup.hs’, then ‘nix-build’ succeeds.
This issue might be reported upstream: they apparently need a configure
step to select the correct name of the C++ compiler.
The following patch also appears to make ‘nix-build’ work.
Regards,
--
Vincent.
```
diff --git a/opencv/Setup.hs b/opencv/Setup.hs
index 031daa1..3c92176 100644
--- a/opencv/Setup.hs
+++ b/opencv/Setup.hs
@@ -3,6 +3,6 @@ import System.Environment ( getArgs )
main = do
args <- getArgs
- let args' | "configure" `elem` args = args ++ ["--with-gcc","g++",
"--with-ld","g++"]
+ let args' | "configure" `elem` args = args
| otherwise = args
defaultMainArgs args'
diff --git a/opencv/opencv.nix b/opencv/opencv.nix
index a28674c..80ed995 100644
--- a/opencv/opencv.nix
+++ b/opencv/opencv.nix
@@ -103,8 +103,8 @@ mkDerivation ({
libraryPkgconfigDepends = [ opencv3 ];
configureFlags =
- [ "--with-gcc=g++"
- "--with-ld=g++"
+ [ "--with-gcc=${stdenv.cc}/bin/c++"
+ "--with-ld=${stdenv.cc}/bin/c++"
];
hardeningDisable = [ "bindnow" ];
```
_______________________________________________
nix-dev mailing list
https://mailman.science.uu.nl/mailman/listinfo/nix-dev
Linus
2017-06-19 22:17:50 UTC
Permalink
Post by Bas van Dijk
Thanks Vincent, you are spot on!
https://github.com/LumiGuide/haskell-opencv/commit/6b78bc4c431d693b0bc828cc86708882a26f777c
Bas
Post by Vincent Laporte
Hi,
Notice that if you replace the two occurrences of ‘g++’ by ‘clang++’
in
Post by Vincent Laporte
the file ‘opencv/Setup.hs’, then ‘nix-build’ succeeds.
This issue might be reported upstream: they apparently need a
configure
Post by Vincent Laporte
step to select the correct name of the C++ compiler.
The following patch also appears to make ‘nix-build’ work.
Regards,
--
Vincent.
```
diff --git a/opencv/Setup.hs b/opencv/Setup.hs
index 031daa1..3c92176 100644
--- a/opencv/Setup.hs
+++ b/opencv/Setup.hs
@@ -3,6 +3,6 @@ import System.Environment ( getArgs )
main = do
args <- getArgs
- let args' | "configure" `elem` args = args ++
["--with-gcc","g++",
Post by Vincent Laporte
"--with-ld","g++"]
+ let args' | "configure" `elem` args = args
| otherwise = args
defaultMainArgs args'
diff --git a/opencv/opencv.nix b/opencv/opencv.nix
index a28674c..80ed995 100644
--- a/opencv/opencv.nix
+++ b/opencv/opencv.nix
@@ -103,8 +103,8 @@ mkDerivation ({
libraryPkgconfigDepends = [ opencv3 ];
configureFlags =
- [ "--with-gcc=g++"
- "--with-ld=g++"
+ [ "--with-gcc=${stdenv.cc}/bin/c++"
+ "--with-ld=${stdenv.cc}/bin/c++"
];
hardeningDisable = [ "bindnow" ];
```
_______________________________________________
nix-dev mailing list
https://mailman.science.uu.nl/mailman/listinfo/nix-dev
I believe stdenv also sets the CC and CXX environment variables to the preferred C compiler, which could be useful to avoid additional nix code.

Linus

Loading...