opencv4nodejs 安装失败记录

报错信息如下:

 CXX(target) Release/obj.target/opencv4nodejs/cc/objdetect/CascadeClassifier.o
In file included from /home/vasia/node/opencvtest/node_modules/native-node-utils/src/NativeNodeUtils.h:10:0,
                 from ../cc/macros.h:1,
                 from ../cc/opencv_modules.h:1,
                 from ../cc/objdetect/objdetect.cc:1:
/home/vasia/node/opencvtest/node_modules/native-node-utils/src/ObjectWrap.h: In constructor ‘FF::ObjectWrapTemplate >::ConstructorBase::ConstructorBase()’:
/home/vasia/node/opencvtest/node_modules/native-node-utils/src/ObjectWrap.h:130:9: error: conversion from ‘FF::ObjectWrapTemplate >::ConstructorBase::__lambda0’ to non-scalar type ‘std::function’ requested
   class ConstructorBase : public BindingBase, public ISyncWorker {
         ^
In file included from ../cc/objdetect/objdetect.cc:7:0:
../cc/objdetect/HOGDescriptor.h: In constructor ‘HOGDescriptor::Constructor::Constructor(Nan::NAN_METHOD_ARGS_TYPE)’:
../cc/objdetect/HOGDescriptor.h:85:47: note: synthesized method ‘FF::ObjectWrapTemplate >::ConstructorBase::ConstructorBase()’ first required here
   Constructor(Nan::NAN_METHOD_ARGS_TYPE info) {
                                               ^
make: *** [Release/obj.target/opencv4nodejs/cc/objdetect/objdetect.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory `/home/vasia/node/opencvtest/node_modules/opencv4nodejs/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 3.10.0-957.21.3.el7.x86_64
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--jobs" "max"
gyp ERR! cwd /home/vasia/node/opencvtest/node_modules/opencv4nodejs
gyp ERR! node -v v12.4.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

是本地 gcc 版本 问题,按照 安装opencv 文章中 gcc 部分, 重新安装 gcc 即可

报错信息如下:

19 errors generated.
make: *** [Release/obj.target/opencv4nodejs/cc/tracking/Trackers/TrackerBoosting.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/Cellar/node@12/12.22.7/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:314:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 20.6.0
gyp ERR! command “/usr/local/Cellar/node@12/12.22.7/bin/node” “/usr/local/Cellar/node@12/12.22.7/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild” “–jobs” “max”
gyp ERR! cwd /usr/local/lib/node_modules/opencv4nodejs
gyp ERR! node -v v12.22.7
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

最终发现是本地安装的 opencv 版本问题
最终跑通版本:

  • opencv4nodejs:5.6.0
  • opencv: 4.5.0

如何安装老版本的opencv

因为是使用 brew 安装的,所以默认安装的是最新版本,所以这里无法使用。
我是通过下载原码,然后手动编译来安装的。下载地址

下载之后进行解压,终端进入解压文件件后按照如下步骤进行安装

mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

安装成功后,就可以愉快的玩耍啦

你可能感兴趣的:(opencv4nodejs 安装失败记录)