Using my native node module with Electron - node.js

So i have built a simple node demo module that works fine with node.exe but when i try to require it with atom electron as a module it does not work even though it was linked with the exact same version of node that my version of electron uses and it the same machine type (x86)
I have tried to use the electron source (node.dll.lib) instead but it I get v8 link errors
What is the excepted way to do this?
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: __thiscall v8::HandleScope::HandleScope(class v8::Isolate *)" (??0HandleScope#v8##QAE#PAVIsolate#1##Z) referenced in function "void __cdecl node::NODE_SET_PROTOTYPE_METHOD(class v8::Local,char const ,void (__cdecl)(class v8::FunctionCallbackInfo const &))" (?NODE_SET_PROTOTYPE_METHOD#node##YAXV?$Local#VFunctionTemplate#v8###v8##PBDP6AXABV?$FunctionCallbackInfo#VValue#v8###3##Z#Z) nodeaddon c:\src\justin\nodeaddon\nodeaddon\myobject.obj 1

According to the docs you'd need to rebuild electron with you native module. The easiest way is to use electron-rebuild, which the team provides.

I ended up setting changing my linker and compiler paths to point to the electron as apposed to the node source source and at all works now.

Related

Problem requiring native c++ addon from electron

Error when I require a Native Addon C++ from electron that works fin from Node.js
Recently I developed my first native C++ Addon for node that works fine with my node project (node version 10.15.0)
The Addon has been built using XCode, which project has been generating using CMake.
I´m having the following error when I use the same native C++ addon from my Electron app.
dyld: lazy symbol binding failed: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeE
Referenced from: /Users/vicentvidal/Documents/Desarrollo/DASNet2/dasaudio/build/DASNetAddon.node
Expected in: flat namespace
dyld: Symbol not found: __ZN2v816FunctionTemplate3NewEPNS_7IsolateEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEENS_5LocalIS4_EENSA_INS_9SignatureEEEiNS_19ConstructorBehaviorENS_14SideEffectTypeE
Referenced from: /Users/vicentvidal/Documents/Desarrollo/DASNet2/dasaudio/build/DASNetAddon.node
Expected in: flat namespace
As I can see the problem appears just when I call from my Electron App
const addon = require('bindings')('DASNetAddon');
which call the following C++ code
static NAN_MODULE_INIT(Init) {
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
tpl->SetClassName(Nan::New("StreamingWorker").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(2);
SetPrototypeMethod(tpl, "sendToAddon", sendToAddon);
constructor().Reset(Nan::GetFunction(tpl).ToLocalChecked());
Nan::Set(target, Nan::New("StreamingWorker").ToLocalChecked(),
Nan::GetFunction(tpl).ToLocalChecked());
}
My Electron version is 3.0.10
My Nan version 2.12.1
My bindings version 1.3.1
Does anybody has any suggestion?
I'm not positive that this is the problem but it is possible that, because the function template is missing your C++ class name, the namespace is coming from somewhere else. Here's one of my Nan Init() functions. The line following the // Prepare constructor template qualifies the New argument with a class namespace.
void Metadata::Init(v8::Local<v8::Object> exports) {
Nan::HandleScope scope;
// Prepare constructor template
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(Metadata::New);
constructor.Reset(ctor);
ctor->InstanceTemplate()->SetInternalFieldCount(2);
ctor->SetClassName(Nan::New("Metadata").ToLocalChecked());
// Prototype
Nan::SetPrototypeMethod(ctor, "copy", Metadata::copy);
Nan::Set(exports, Nan::New("Metadata").ToLocalChecked(), ctor->GetFunction());
}
I haven't tried running/loading in an Electron environment, nor on a Mac, so I can only say this works fine on Linux. But because your error message refers to "FunctionTemplate3New" it's a guess.

VS2013 VC++ libcurl LNK2028 LNK2019 linking errors

I'm trying to get Libcurl working in my VC++ project on VS2013 Community. I've been toiling with this for many hours, and I've tried essentially everything on Stack and Google about it, to no avail.
My most recent attempt was sparked by this answer, that mentions libcurl as a Nuget package. This is good, because it comes with all of the .lib files required. I have however run into the same problem as this fellow, in that I'm getting a linker error.
I'm importing the following libraries as 'Additional Dependencies' in the Project Configuration settings under Linker -> Input:
libcurl.lib;libeay32.lib;ssleay32.lib;Ws2_32.lib;libssh2.lib;zlib.lib;wldap32.lib;
Obviously, each one of these .lib files is in a different directory inside the nuget package folder inside the project folder, so under Linker -> General my 'Additional Library Directories' is set to:
"PATHTOPROJECT\packages\curl.7.30.0.2\build\native\lib\v110\x64\Release\static";
"PATHTOPROJECT\packages\zlib.1.2.8.1\build\native\lib\v110\Win32\Release\static\cdecl";
"PATHTOPROJECT\packages\openssl.1.0.1.21\build\native\lib\v110\x64\Release\static\cdecl";
"PATHTOPROJECT\packages\libssh2.1.4.3.1\build\native\lib\v110\x64\Release\static\cdecl";
I am trying to use static libraries, because I don't want to drag .dll's with my project executable if I can avoid it. It's also worth noting that my most recent attempt at using libcurl also includes SSL and whatnot, but I don't actually need those extras. Really, I just need a static libcurl library, but I can't find or compile one it seems.
In my code, I'm also using this include: #include "curl/curl.h"
I've also added the Additional Include directory correctly under 'Additional Include Directories' under C/C++ -> General:
PROJECTPATH\packages\curl.7.30.0.2\build\native\include
Now, this all compiles fine as long as I don't try and use curl in the project code.
So, the errors when I do try and use curl in the code:
CURL *curl;
curl = curl_easy_init();
That piece of code generates these errors:
1>Main.obj : error LNK2028: unresolved token (0A000453) "extern "C" void * __cdecl curl_easy_init(void)" (?curl_easy_init##$$J0YAPAXXZ) referenced in function "private: class System::String ^ __clrcall Project::Main::CurlRequest(class System::String ^,class System::String ^,class System::String ^,class System::String ^)" (?CurlRequest#Main#Project##$$FA$AAMP$AAVString#System##P$AAV34#000#Z)
1>Main.obj : error LNK2019: unresolved external symbol "extern "C" void * __cdecl curl_easy_init(void)" (?curl_easy_init##$$J0YAPAXXZ) referenced in function "private: class System::String ^ __clrcall Project::Main::CurlRequest(class System::String ^,class System::String ^,class System::String ^,class System::String ^)" (?CurlRequest#Main#Project##$$FA$AAMP$AAVString#System##P$AAV34#000#Z)
There is of course more to my curl using code, but that bare minimum shows the basics of the linking error. What can I do to fix this? As I mentioned before I've tried a whole range of solutions, some of which I'll list below:
Many answers to the questions regarding problems using libcurl in VS projects mention downloading libcurl from http://curl.haxx.se/latest.cgi?curl=win32-devel-msvc, but that link doesn't work as of now, so I can't use it.
More answers say to just compile libcurl from source. The source comes with .vcproj files, none of which compile for me without hundreds of errors, so that's out.
Solved.
This Github project is a .bat file that downloads the libcurl source, compiles it, and makes the libraries (both static and dynamic). Importing the static library created by this (libcurl_a.lib) and using it in my project along with the include directory has worked.
I'll leave this question with an unaccepted answer in case someone can provide other helpful steps that would have fixed the problem I had in using the nuget package installation.
Finally.

Compile V8 modules in windows

I'm trying to compile a module with V8 and Node. I configured it to be dll and downloaded the source code and compiled nodejs with vcbuild.bat.
However, it throws errors like
Error 2 error LNK2028: unresolved token (0A0005F6) "class v8::Handle __cdecl v8::True(void)" (?True#v8##$$FYA?AV?$Handle#VBoolean#v8###1#XZ) referenced in function "public: static class v8::Handle __cdecl v8::Boolean::New(bool)" (?New#Boolean#v8##$$FSA?AV?$Handle#VBoolean#v8###2#_N#Z)
or
Error 6 error LNK2028: unresolved token (0A0005FE) "public: class
v8::Local __thiscall
v8::Object::GetPropertyNames(void)"
(?GetPropertyNames#Object#v8##$$FQAE?AV?$Local#VArray#v8###2#XZ)
referenced in function "class v8::Handle __cdecl
strin(class v8::Arguments const &)"
(?strin##$$FYA?AV?$Handle#VValue#v8###v8##ABVArguments#2##Z) c:\Users\aisha\documents\visual
studio 2012\Projects\Project2\Project2\EventLog.obj EventLog
what can be wrong? Seems to be related to the object HandleScope
I have built node with v8 dll on Windows (VS2010). I record what I did to share with you all and also for my reference. The packages are fresh clones from git on this day.
First you build v8 as a dll. I used the method BitCortex suggested in this page.
Build googles v8 as shared library on windows?
And then
0) Suppose you are at the root of the source tree.
1) edit vcbuild.bat (for a debug build)
Line 15 set config=Release -> set config=Debug
Line 18 set target_arch=ia32 -> set target_arch=x64
* target-arch should be the arch of your system.
Line 92 python configure %debug_arg% %nosnapshot_arg% %noetw_arg% %noperfctr_arg% --dest-cpu=%target_arch% --tag=%TAG%
-> python configure %debug_arg% %nosnapshot_arg% %noetw_arg% %noperfctr_arg% --dest-cpu=%target_arch% --tag=%TAG% --shared-v8
2) cp $(v8-dll-build)/include/*h ./src
3) cp $(v8-dll-build)/build/Debug/lib/v8.lib .
4) Build
> vcbuild nosign
5) cp $(v8-dll-build)/build/Debug/*.dll Debug
That is all there is to it.

SFML linker problems on eclipse VC++

I am trying to use the SFML library for audio in my project.
I am developing in eclipse juno for c++ and am using SFML v1.6.
I added sfml-audio-d.lib, sfml-main-d.lib, and sfml-system-d.lib into
C/C++ General > paths and symbols>libraries
I also defined a macro named SFML_DYNAMIC into
C/C++ Build>Settings>C++ Compiler>Preprocessor 'Defines /D' section
I added the directory that contains all the dlls into the PATH environment variable.
In my code I make use of sf::SoundBuffer, but when I try to build the project I get the following linker error:
Chunk.obj : error LNK2001: unresolved external symbol "private: static class sf::SoundBuffer * Chunk::breakBlockSound" (?breakBlockSound#Chunk##0PAVSoundBuffer#sf##A)
MyProject.exe : fatal error LNK1120: 1 unresolved externals
Had to rebuild the project in VS2010 before using it. Works now.

Linker Error: Precombiled Library VC++ 6.0 with VC++ 8.0 Program

I am trying to recompile some code I have for a new system. It involves a precompiled static library that I do not have the source code for (just the header), and this library was built with VC++ 6.0 or older with the older runtime libraries. On my old system, which had VC++ 6.0, my program was built and ran fine, but I have recently upgraded things and I no longer have access to VC++ 6.0, only Express 2008 (9.0 w/ SP).
When I build the solution, it compiles but has the following linker error:
1>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall
std::_Lockit::~_Lockit(void)" (??1_Lockit#std##QAE#XZ) already defined
in NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005:
"public: __thiscall std::bad_cast::bad_cast(char const *)"
(??0bad_cast#std##QAE#PBD#Z) already defined in NOREC.lib(track.obj)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: __thiscall
std::bad_cast::bad_cast(class std::bad_cast const &)"
(??0bad_cast#std##QAE#ABV01##Z) already defined in
NOREC.lib(track.obj) 1>LIBCMT.lib(stdexcpt.obj) : error LNK2005:
"public: virtual __thiscall std::bad_cast::~bad_cast(void)"
(??1bad_cast#std##UAE#XZ) already defined in NOREC.lib(track.obj)
1>LINK : fatal error LNK1104: cannot open file 'libcp.lib'
Any ideas how to overcome this issue would be very welcome.
From the last link error, libcp.lib cannot be found. This library has been removed as of VS 2005. Use /MT for the multithreaded version.
http://msdn.microsoft.com/en-us/library/abx4dbyh%28v=vs.80%29.aspx
The multithreaded version is libcpmt.lib which you will get automatically with the /MT flag. I see in the first error you are using libcpmtd.lib which is the debug version of the same. I'm not sure how you are getting that if you are not using /MTd. (or if you are, how libcp.lib is referenced since you should be using one or the other, not both)
The linker is telling you that some symbols are defined more than once. The brute force to convice the linker to produce your target image is to use the /FORCE:MULTIPLE as explained here. I used to use this switch a few times.
LINK : fatal error LNK1104: cannot open file 'libcp.lib'
This is a bug in the linker. Just create an empty file named libcp.lib in the LIBPATH.
libcp.lib you can find in installed MS Visual Studio 6.0 in
c:\Program Files\Microsoft Visual Studio\VC98\Lib\
directory.
Just copy it to your MSVS 2005/2008/2010 lib directory
(i.e. c:\Program Files\Microsoft Visual Studio 8\VC\lib\)
And everything will compiled just fine.

Resources