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?
An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | 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 seems to be successfull
yarn --verbose build output.txt
I am having this identical issue on Mac OS 10.15.1. Autobuild runs fine, but Electron rebuild fails with same error.
Got same error on windows.
I checked sln file, it seems including dir was not added when running electron-build.
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?
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
@justadudewhohacks would adding C:\tools\opencv\build\include to build/opencv4nodejs.vcxproj in properties -> Configurations Properties -> C/C++ -> General -> Additional Include Directories help?
I have seen others using this solution, but when I go to electron-build the sln is obviously overwritten without this modification. (Windows 10, project _not_ in a white-spaced directory)
Cheers!
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 [email protected]. 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.
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
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
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/opencv2Having 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.nodeI'm using mac osx 10.14.6
Have you solved that problem ?
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:
5.3.0. The version before (5.2.0) worked fine for meopencv2/core.hpp file not found error, it seems that the defaultIncludeDirs are defined correctly, but somehow might not be triggered? - see install.jsSymbol not found error, I am not exactly sure, but believe it has something todo with the libraries not being set/linked correctly.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?
Facing the same issue as @fakob
Is there any known workaround?
(reverting to 5.2.0 fixes the include + linking issues)
Hi @cyrildiagne, unfortunately I do not know any other than reverting to 5.2.0.
The other day I gave it another shot disabling the autoBuild feature, but I ran into the same issue again. Sorry.
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
Really helpful! Thanks~
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
I am getting the same issue in electron on Windows, check below, with the following setup
"dependencies": {
"electron": "10.1.4",
"electron-rebuild": "2.3.2",
"opencv4nodejs": "5.6.0"
},
"opencv4nodejs": {
"disableAutoBuild": 1,
"opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
"opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc14\\lib",
"opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc14\\bin"
}
fatal error: 'opencv2/core.hpp' file not found
Most helpful comment
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