opencv4nodejs: Error when rebuilding - fatal error: 'opencv2/core.hpp' file not found

Today I was upgrading from opencv4nodejs 4.9.1 to 5.3.0 when I ran into this error.

I am using opencv4nodejs in an electron environment and there the below listed error message is triggered when using electron-rebuild, which I guess is similar to this command as it produces more or less the same error.

node-gyp rebuild --jobs max

The building of both opencv4nodejs and opencv-build seems to work fine. The build output has lots of warnings, but ends successfully (see attached file). After that the error is thrown when rebuilding gets triggered.

I have looked at these issues but their solutions do not work for me https://github.com/justadudewhohacks/opencv4nodejs/issues/591 - I do not have tesseract installed https://github.com/justadudewhohacks/opencv4nodejs/issues/618 - disabling autobuild is currently not an option for me

Anyone an idea? In the build files I saw that opencv 3.4.6 gets installed by default. Might it make a difference if one builds opencv 4.x with autoBuildOpencvVersion?

Error Message

An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@5.0.5
gyp info using node@12.4.0 | darwin | x64
gyp info find Python using Python version 2.7.16 found at "/usr/local/opt/python@2/bin/python2.7"
gyp info spawn /usr/local/opt/python@2/bin/python2.7
gyp info spawn args [
gyp info spawn args   '/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/node_modules/electron-rebuild/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/app/node_modules/opencv4nodejs/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/node_modules/electron-rebuild/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/fakob/.electron-gyp/4.2.10/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/fakob/.electron-gyp/4.2.10',
gyp info spawn args   '-Dnode_gyp_dir=/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/node_modules/electron-rebuild/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/fakob/.electron-gyp/4.2.10/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/app/node_modules/opencv4nodejs',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CXX(target) Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o
In file included from ../cc/opencv4nodejs.cc:2:
In file included from ../cc/ExternalMemTracking.h:1:
../cc/macros.h:2:10: fatal error: 'opencv2/core.hpp' file not found
#include <opencv2/core.hpp>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/node_modules/electron-rebuild/node_modules/node-gyp/lib/build.js:194: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 Darwin 18.7.0
gyp ERR! command "/usr/local/Cellar/node/12.4.0/bin/node" "/Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/node_modules/electron-rebuild/node_modules/.bin/node-gyp" "rebuild" "--target=4.2.10" "--arch=x64" "--dist-url=https://electronjs.org/headers" "--build-from-source"
gyp ERR! cwd /Users/fakob/_jakob/work/fakob_MoviePrintApp_130515/03_Programming/02_Setups/05_Electron/MoviePrint_v004/app/node_modules/opencv4nodejs
gyp ERR! node -v v12.4.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok 

Failed with exit code: 1

Auto Build - Full Error Log

auto build seems to be successfull yarn --verbose build output.txt

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 6
  • Comments: 20 (1 by maintainers)

Most upvoted comments

With Ubuntu 18.04 OpenCV 4.1.0. I make a link to solve this problem. ln -s /usr/local/include/opencv4/opencv2/ /usr/local/include/opencv2

ln -s /usr/local/include/opencv4/opencv2/ /usr/local/include/opencv2

Thanks, this approach solved the issue for me on macOS Catalina and openCV installed via homebrew: ln -s /usr/local/Cellar/opencv/4.2.0_1/include/opencv4/opencv2 /usr/local/Cellar/opencv/4.2.0_1/include/opencv2

I have done some more testing on mac and windows, but, spoiler alert, I am stuck with the same issues as everyone else. But for what its worth here are my findings:

  • The issue started with 5.3.0. The version before (5.2.0) worked fine for me
  • Regarding the opencv2/core.hpp file not found error, it seems that the defaultIncludeDirs are defined correctly, but somehow might not be triggered? - see install.js
  • Regarding the Symbol not found error, I am not exactly sure, but believe it has something todo with the libraries not being set/linked correctly. Maybe @justadudewhohacks has some ideas to point me into the right direction?

Details

My setup

My tests To get around the

In file included from ../cc/opencv4nodejs.cc:2:
In file included from ../cc/ExternalMemTracking.h:1:
../cc/macros.h:2:10: fatal error: 'opencv2/core.hpp' file not found
#include <opencv2/core.hpp>
         ^~~~~~~~~~~~~~~~~~

error I had added the include directory path in theapp/node_modules/opencv4nodejs/binding.gyp

"include_dirs" : [
	"<!@(node ./install/parseEnv.js OPENCV4NODEJS_INCLUDES)",
	"cc",
	"cc/core",
	"<!(node -e \"require('nan')\")",
	"<!(node -e \"require('native-node-utils')\")",
	"<(module_root_dir)/../opencv-build/opencv/build/include",
],

I have used the autoBuildOpencvVersion to test if opencv4 makes any difference, but it did not. For opencv 4 the include path is slightly different

	"<(module_root_dir)/../opencv-build/opencv/build/include/opencv4",

After having fixed the include issue electron-rebuild ends successfully. But when running the application, the Symbol not found error pops up.

Uncaught Error: dlopen(/Users/jakobschindegger/Documents/Electron/electron-opencv4nodejs/app/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node, 1): Symbol not found: __ZNK2cv12MatAllocator23getBufferPoolControllerEPKc
  Referenced from: /Users/jakobschindegger/Documents/Electron/electron-opencv4nodejs/app/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node
  Expected in: flat namespace
 in /Users/jakobschindegger/Documents/Electron/electron-opencv4nodejs/app/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node

This is where I am stuck now. I am not sure how to solve this error. I had looked at this issue where it seemed that they solved the error, but their solution did not work for me. Maybe because they were not using the autoBuild feature?

Edit: My last suggestion was using the install from opencv’s site, not chocolatey. I actually don’t think that was the cause, instead I had to use opencv4nodejs@5.1.0. Note that this will not work if you just change your package.json entry to ^5.1.0, as this will simply install 5.5.0 again.

As to why windows freaks out with 5.5.0, I couldn’t tell you, but I hope this helps someone.

maybe you should try @u4/opencv4nodejs this original opencv4nodejs is not maintained anymore.

Facing the same issue on MacOS Monterey, while running npm i opencv4nodejs and none of the above mentioned steps worked. Installed opencv using brew after setting export OPENCV4NODEJS_DISABLE_AUTOBUILD=1 as mentioned here

@fakob Hi, I got the same issue as yours. Did you figure out the workaround? 🙇

Error: dlopen(/Users/zcmgyu/Documents/LongWorkingSpace/matt/opencv4nodejs/build/Release/opencv4nodejs.node, 0x0001): symbol not found in flat namespace ‘__ZNK2cv12MatAllocator23getBufferPoolControllerEPKc’

ln -s /usr/local/include/opencv4/opencv2/ /usr/local/include/opencv2

Thanks, this approach solved the issue for me on macOS Catalina and openCV installed via homebrew: ln -s /usr/local/Cellar/opencv/4.2.0_1/include/opencv4/opencv2 /usr/local/Cellar/opencv/4.2.0_1/include/opencv2

I tried to do this approach on macOS Catalina 10.15.6 and it didn’t work

With Ubuntu 18.04 OpenCV 4.1.0. I make a link to solve this problem. ln -s /usr/local/include/opencv4/opencv2/ /usr/local/include/opencv2

Having this issue when creating a symlink

dlopen(/Users/ianoderon/Desktop/dev/cam/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node, 1): Symbol not found: __ZNK2cv12MatAllocator23getBufferPoolControllerEPKc
  Referenced from: /Users/ianoderon/Desktop/dev/cam/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node
  Expected in: flat namespace
 in /Users/ianoderon/Desktop/dev/cam/node_modules/opencv4nodejs/build/Release/opencv4nodejs.node

I’m using mac osx 10.14.6

The same problem here. Seems that electron-rebuild can’t include opencv2/core.hpp and i can’t find opencv2/core.hpp myself. Is there any solution to this problem?