I'm trying to build a node addon using the opencv library. I'm compiling it using node-gyp.
I've achieved to link opencv using the binding.gyp
config file, but I have some issues with the v8 library.
Here is my binding.gyp file:
"targets": [
{
"target_name": "test",
"sources": [ "src/native/test.cpp" ],
"include_dirs": [
"/usr/local/include/opencv4",
"/usr/local/include/node",
"/usr/include"
],
"library_dirs": [ "/usr/local/lib", "/usr/lib" ],
"libraries": [
"/usr/local/lib/libopencv_core.so",
"/usr/local/lib/libopencv_videoio.so",
"/usr/local/lib/libopencv_highgui.so",
"/usr/lib/libv8.so"
],
"ldflags": [ "-Wl,-z,defs" ],
"link_settings": {
"libraries": [
"-lopencv_core",
"-lopencv_videoio",
"-lopencv_highgui",
"-lv8",
"-lpthread"
]
}
}
]
}
Without linking opencv, I haven't any problem to build and run my addon, but as soon as I link opencv, the build failed because of v8:
test.cpp:(.text+0x1f9): undefined reference to `v8::V8::ToLocalEmpty()'
test.cpp:(.text+0x209): undefined reference to `v8::V8::FromJustIsNothing()'
test.cpp:(.text+0x219): undefined reference to `v8::V8::ToLocalEmpty()'
test.cpp:(.text+0x229): undefined reference to `v8::V8::ToLocalEmpty()'
test.cpp:(.text+0x239): undefined reference to `v8::V8::FromJustIsNothing()'
... and so on
As you can see in the binding.gyp file, I've tried to link the corresponding libraries and include for v8, but it doesn't make it.
I'm pretty sure it's a problem or a conflict with the configuration itself, because without linking opencv, the build works great and I've no problems to use the addon in a nodeJS file.
My c++ file is very simple, it's as simple as possible since I just want it to build and link libraries correctly:
#include <opencv4/opencv2/core.hpp>
#include <opencv4/opencv2/videoio.hpp>
#include <opencv4/opencv2/highgui.hpp>
#include <node/v8.h>
#include <node/node.h>
#include <iostream>
#include <stdio.h>
void capture(const v8::FunctionCallbackInfo<v8::Value>& args)
{
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
cv::Mat frame;
cv::VideoCapture cap;
}
void Initialize(v8::Local<v8::Object> exports) {
NODE_SET_METHOD(exports, "capture", capture);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
If you have any ideas about this build error, and why v8 isn't linking correctly when linking opencv, I would appreciate any help,
Thanks