justadudewhohacks/opencv4nodejs

opencv2/core.hpp: No such file or directory install error

tuonidaici opened this issue · 4 comments

npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! In file included from ../cc/ExternalMemTracking.h:1:0,
npm ERR! from ../cc/opencv4nodejs.cc:2:
npm ERR! ../cc/macros.h:2:28: fatal error: opencv2/core.hpp: No such file or directory
npm ERR! #include <opencv2/core.hpp>

i have the same error

Link of the documentation concerning the missing dependency when executing make BUILDTYPE=Release -C build :
https://docs.opencv.org/master/d0/de1/group__core.html#ga719ebd4a73f30f4fab258ab7616d0f0f

Edit: The file isn't found because the library opencv2 isn't built

I came to this conclusion when i tried to run npm run install inside the opencv4nodejs module. This module needs the opencv-build node module and uses it to compile the opencv2 library.

How to solve it :

Install the opencv4nodejs node module in your project without autobuild

export OPENCV4NODEJS_DISABLE_AUTOBUILD=1
npm install --save opencv4nodejs 

Compile it manually from the opencv-build sub node module

cd ./node_modules/opencv4nodejs/node_modules/opencv-build
npm run install # will start compiling opencv2

Once the library compiled, you can start over the opencv4nodejs installation

cd ../..
npm run install
cd ./node_modules/opencv4nodejs/node_modules/opencv-build
npm run install # will start compiling opencv2

I keep encountering a strange error with npm, it appears to be looking for "gmake" but it can't find it. Make and the other command line tools for Xcode are properly installed, and have even be reinstalled in an attempt to correct this issue, to no avail. Here's my log:

-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- The C compiler identification is AppleClang 12.0.5.12050022
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - broken
CMake Error at /usr/local/Cellar/cmake/3.21.2/share/cmake/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make -f Makefile cmTC_0bbdb/fast && gmake  -f CMakeFiles/cmTC_0bbdb.dir/build.make CMakeFiles/cmTC_0bbdb.dir/build
    make: gmake: No such file or directory
    make: *** [cmTC_0bbdb/fast] Error 1


  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:135 (project)


-- Configuring incomplete, errors occurred!
See also "/usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/CMakeFiles/CMakeOutput.log".
See also "/usr/local/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv/build/CMakeFiles/CMakeError.log".
ERR! child process exited with code 1 (for more info, set '--loglevel silly')
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build@0.1.9 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the opencv-build@0.1.9 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

Hi,
Great news for those people that do not want to build their OpenCV:
I published @u4/opencv4nodejs V 6.2.4 today,

This version autodetects the common setup path for Brew on Mac, Chocolatey on Windows, and Apt on Linux.

  • Windows:

choco install opencv

  • Mac:

brew install opencv

  • debian:

apt -y install libopencv-contrib-dev libopencv-dev

just define environment variable: OPENCV4NODEJS_DISABLE_AUTOBUILD=1

And your prebuild OpenCV will be used.

You may need to call:
npx build-opencv rebuild
or
npx build-opencv --nobuild rebuild (if you do not define OPENCV4NODEJS_DISABLE_AUTOBUILD variable)