Electron rebuild with own version of OpenCV
spstrademark opened this issue · 3 comments
OpenCV version:: 4.1.2
OpenCV-contrib : No
Nodejs version: 14.15.3
OS: Windows 10
I have been struggling to add opencv4nodejs to my electron app for days now with no success so i gave up and decided to ask what am i doing wrong? I have installed windows-build-tools using the following command
npm install --global windows-build-tools
My dependencies in my package.json look like this :
"dependencies": {
"electron": "^10.2.0",
"opencv4nodejs": "^5.6.0"
},
"devDependencies": {
"electron-rebuild": "^2.3.4"
},
"opencv4nodejs": {
"disableAutoBuild": 1,
"opencvIncludeDir": "C:\\tools\\opencv\\build\\include",
"opencvLibDir": "C:\\tools\\opencv\\build\\x64\\vc15\\lib",
"opencvBinDir": "C:\\tools\\opencv\\build\\x64\\vc15\\bin"
}
I have installed OpenCV version 4.1.2 with the following command
choco install OpenCV -y -version 4.1.2
My environmental variables look like this
OPENCV_INCLUDE_DIR = C:\tools\opencv\build\include
OPENCV_LIB_DIR = C:\tools\opencv\build\x64\vc15\lib
OPENCV_BIN_DIR = C:\tools\opencv\build\x64\vc15\bin
and i have appended %OPENCV_BIN_DIR% to Path My npm install passes successfully, and the issues come when i try to run electron rebuild with the following script
"electron-rebuild": "electron-rebuild -w opencv4nodejs" Initially i had the error that it cound not find opencv2/core.hpp but i have fixed that by adding the following lines to the binding.gyp file located in node_modules/opencv4nodejs
"include_dirs" : [
"C:\\tools\\opencv\\build\\include"
"<!@(node ./install/parseEnv.js OPENCV4NODEJS_INCLUDES)",
"cc",
"cc/core",
"<!(node -e \"require('nan')\")",
"<!(node -e \"require('native-node-utils')\")"
],
'link_settings': {
'libraries': [
'-lopencv_world412.lib'
],
'library_dirs': [
'"C:\\tools\\opencv\\build\\x64\\vc15\\lib',
],
},
Now the rebuild starts but at some point i get the error
/ Building module: opencv4nodejs, Completed: 0LINK : fatal error LNK1104: cannot open file 'uiAccess='false' \manifest:embed \DEBUG \PDB:D:\Projects\TE\plain-js\node_modules\opencv4nodejs\build\Release\opencv4nodejs.pdb' [D:\Projects\TE\plain-js\node_modules\opencv4nodejs\build\opencv4nodejs.vcxproj]
× Rebuild Failed
Before running the rebuild script i have noticed that in the directory build\Release are the following files
but when i get the specified error i only have an obj folder. What am i doing wrong and what should be changed in order the electron-build to finish successfully?
Thank you for your time!
Your errors don't look familiar to me. However, I managed to package opencv4nodejs 5.2.0 with electron 5.0.6. I used a script to fix and include the dependencies to system libraries which were linked by opencv libraries. I don't know if that's the right way to do it, but it worked. Contact me if you think I can be of help.
Your solution only fixes for Darwin/mac OP and I are having issues with Windows.
For me, I got it to bundle into the installer, but on install it can't find the deps. So a little more gnarly
Check out this project, it works for win and mac: https://github.com/fakob/MoviePrint_v004
For windows a simple dll copy instruction in the package.json helped in my case.