Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fakob opened this issue Oct 16, 2019 · 20 comments
Open

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

fakob opened this issue Oct 16, 2019 · 20 comments

Comments

@fakob
Copy link

fakob commented Oct 16, 2019

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
#591 - I do not have tesseract installed
#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

@ztaylor54
Copy link

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

@tdzl2003-deploy
Copy link

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

@P0oOOOo0YA
Copy link

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?

@AMoreaux
Copy link

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

@Vaspra
Copy link

Vaspra commented Feb 3, 2020

@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
Copy link

Vaspra commented Feb 3, 2020

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.

@benmarten
Copy link

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

@darknblack
Copy link

darknblack commented Feb 25, 2020

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

@tears743
Copy link

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 ?

@fakob
Copy link
Author

fakob commented May 1, 2020

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?

@cyrildiagne
Copy link

cyrildiagne commented Aug 8, 2020

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

@fakob
Copy link
Author

fakob commented Aug 9, 2020

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.

@julianakuei
Copy link

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~

@luisantos1986
Copy link

luisantos1986 commented Sep 19, 2020

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

@AramAnd
Copy link

AramAnd commented Oct 24, 2020

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

@zcmgyu
Copy link

zcmgyu commented Dec 14, 2021

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

@fakob
Copy link
Author

fakob commented Dec 20, 2021

No sorry @zcmgyu, still the same as before.
#645 (comment)

@zcmgyu
Copy link

zcmgyu commented Dec 20, 2021

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

@rajvigohil2411
Copy link

rajvigohil2411 commented Dec 21, 2022

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

@UrielCh
Copy link
Contributor

UrielCh commented Dec 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests