opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

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

Open fakob opened this issue 6 years ago • 20 comments

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 [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 - ~~Full Error Log~~

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

fakob avatar Oct 16 '19 22:10 fakob

I am having this identical issue on Mac OS 10.15.1. Autobuild runs fine, but Electron rebuild fails with same error.

ztaylor54 avatar Nov 04 '19 00:11 ztaylor54

Got same error on windows. I checked sln file, it seems including dir was not added when running electron-build.

tdzl2003-deploy avatar Nov 11 '19 04:11 tdzl2003-deploy

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?

P0oOOOo0YA avatar Dec 21 '19 10:12 P0oOOOo0YA

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

AMoreaux avatar Jan 15 '20 17:01 AMoreaux

@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!

Vaspra avatar Feb 03 '20 00:02 Vaspra

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.

Vaspra avatar Feb 03 '20 14:02 Vaspra

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

benmarten avatar Feb 15 '20 22:02 benmarten

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

darknblack avatar Feb 25 '20 19:02 darknblack

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

Have you solved that problem ?

tears743 avatar Apr 21 '20 08:04 tears743

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?

fakob avatar May 01 '20 07:05 fakob

Facing the same issue as @fakob Is there any known workaround? (reverting to 5.2.0 fixes the include + linking issues)

cyrildiagne avatar Aug 08 '20 08:08 cyrildiagne

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.

fakob avatar Aug 09 '20 21:08 fakob

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~

julianakuei avatar Aug 21 '20 10:08 julianakuei

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

luisantos1986 avatar Sep 19 '20 01:09 luisantos1986

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

AramAnd avatar Oct 24 '20 11:10 AramAnd

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

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

zcmgyu avatar Dec 14 '21 14:12 zcmgyu

No sorry @zcmgyu, still the same as before. https://github.com/justadudewhohacks/opencv4nodejs/issues/645#issuecomment-671104335

fakob avatar Dec 20 '21 18:12 fakob

Thanks 🙇 I gave it up. I'm trying using OpenCV.js instead.

https://docs.opencv.org/4.5.4/dc/de6/tutorial_js_nodejs.html

zcmgyu avatar Dec 20 '21 21:12 zcmgyu

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

rajvigohil2411 avatar Dec 21 '22 12:12 rajvigohil2411

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

UrielCh avatar Dec 22 '22 07:12 UrielCh