Closed marcus-sa closed 5 years ago
Hi @marcus-sa, I tried to solve your problem, but I have only macOS and I only changed the CMake file like reported here. Essentially I replaced this part of your configuration:
# Include N-API wrappers
execute_process(COMMAND node -p "require('node-addon-api').include"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE NODE_ADDON_API_DIR
)
string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
with this:
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/node_modules/node-addon-api
${CMAKE_SOURCE_DIR}/node_modules/node-addon-api/src
${CMAKE_JS_INC})
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB})
Furthermore I added this line at the begin of make file set (CMAKE_CXX_STANDARD 11)
All worked good for me, could you try if my solution works for you?
@NickNaso Thanks a lot for trying to help. I'll see if your changes fixes the issues once I'm home. I'm quite new to C++ and N-API in general, so my knowledge probably wasn't enough to solve it on my own ☺️
It did make a difference, but now I just end up with a bunch of LNK2019
and LNK2001
errors being thrown.
What versions of cmake, node and C++ compiler are you using?
LINK : warning LNK4199: /DELAYLOAD:NODE.EXE ignored; no imports found from NODE.EXE [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_module_register referenced in function _register_Cerberus [C:\Users\marcu\Git\venobo\cerberus\build\Cerber
us.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_get_last_error_info referenced in function "public: static class Napi::Error __cdecl Napi::Error::New(stru
ct napi_env__ *)" (?New@Error@Napi@@SA?AV12@PEAUnapi_env__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_get_last_error_info [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_fatal_error referenced in function "protected: __cdecl Napi::Reference<class Napi::Object>::Reference<clas
s Napi::Object>(class Napi::Reference<class Napi::Object> const &)" (??0?$Reference@VObject@Napi@@@Napi@@IEAA@AEBV01@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerbe
rus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_fatal_error [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_create_string_utf8 referenced in function "public: static class Napi::Error __cdecl Napi::Error::New(struc
t napi_env__ *)" (?New@Error@Napi@@SA?AV12@PEAUnapi_env__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_create_string_utf8 [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_create_error referenced in function "public: static class Napi::Error __cdecl Napi::Error::New(struct napi
_env__ *)" (?New@Error@Napi@@SA?AV12@PEAUnapi_env__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_create_error [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_create_type_error referenced in function "public: static class Napi::Error __cdecl Napi::Error::New(struct
napi_env__ *)" (?New@Error@Napi@@SA?AV12@PEAUnapi_env__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_create_type_error [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_get_value_string_utf8 referenced in function "public: class std::basic_string<char,struct std::char_traits
<char>,class std::allocator<char> > const & __cdecl Napi::Error::Message(void)const " (?Message@Error@Napi@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D
@2@@std@@XZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_get_value_string_utf8 [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_get_named_property referenced in function "public: class std::basic_string<char,struct std::char_traits<ch
ar>,class std::allocator<char> > const & __cdecl Napi::Error::Message(void)const " (?Message@Error@Napi@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@
@std@@XZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_get_named_property [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_create_reference referenced in function "protected: __cdecl Napi::Reference<class Napi::Object>::Reference
<class Napi::Object>(class Napi::Reference<class Napi::Object> const &)" (??0?$Reference@VObject@Napi@@@Napi@@IEAA@AEBV01@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\
Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_create_reference [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_delete_reference referenced in function "public: virtual __cdecl Napi::Error::~Error(void)" (??1Error@Napi
@@UEAA@XZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_delete_reference [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_get_reference_value referenced in function "protected: __cdecl Napi::Reference<class Napi::Object>::Refere
nce<class Napi::Object>(class Napi::Reference<class Napi::Object> const &)" (??0?$Reference@VObject@Napi@@@Napi@@IEAA@AEBV01@@Z) [C:\Users\marcu\Git\venobo\cerberus\bui
ld\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_get_reference_value [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_open_handle_scope referenced in function "protected: __cdecl Napi::Reference<class Napi::Object>::Referenc
e<class Napi::Object>(class Napi::Reference<class Napi::Object> const &)" (??0?$Reference@VObject@Napi@@@Napi@@IEAA@AEBV01@@Z) [C:\Users\marcu\Git\venobo\cerberus\build
\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_open_handle_scope [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_close_handle_scope referenced in function "protected: __cdecl Napi::Reference<class Napi::Object>::Referen
ce<class Napi::Object>(class Napi::Reference<class Napi::Object> const &)" (??0?$Reference@VObject@Napi@@@Napi@@IEAA@AEBV01@@Z) [C:\Users\marcu\Git\venobo\cerberus\buil
d\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_close_handle_scope [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_open_escapable_handle_scope referenced in function "public: class std::basic_string<char,struct std::char_
traits<char>,class std::allocator<char> > const & __cdecl Napi::Error::Message(void)const " (?Message@Error@Napi@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$alloc
ator@D@2@@std@@XZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_open_escapable_handle_scope [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_close_escapable_handle_scope referenced in function "public: __cdecl Napi::EscapableHandleScope::~Escapabl
eHandleScope(void)" (??1EscapableHandleScope@Napi@@QEAA@XZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_close_escapable_handle_scope [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_escape_handle referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,c
lass std::allocator<char> > const & __cdecl Napi::Error::Message(void)const " (?Message@Error@Napi@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@
@XZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_escape_handle [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_throw referenced in function "public: void __cdecl Napi::Error::ThrowAsJavaScriptException(void)const " (?
ThrowAsJavaScriptException@Error@Napi@@QEBAXXZ) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_throw [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_is_exception_pending referenced in function "public: static class Napi::Error __cdecl Napi::Error::New(str
uct napi_env__ *)" (?New@Error@Napi@@SA?AV12@PEAUnapi_env__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_is_exception_pending [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
Cerberus.obj : error LNK2019: unresolved external symbol napi_get_and_clear_last_exception referenced in function "public: static class Napi::Error __cdecl Napi::Error:
:New(struct napi_env__ *)" (?New@Error@Napi@@SA?AV12@PEAUnapi_env__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2001: unresolved external symbol napi_get_and_clear_last_exception [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_get_undefined referenced in function "struct napi_value__ * __cdecl Napi::details::WrapCallback<clas
s <lambda_04785c1abc4759ec667a151abddba1d6> >(class <lambda_04785c1abc4759ec667a151abddba1d6>)" (??$WrapCallback@V<lambda_04785c1abc4759ec667a151abddba1d6>@@@details@Na
pi@@YAPEAUnapi_value__@@V<lambda_04785c1abc4759ec667a151abddba1d6>@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_create_symbol referenced in function "private: static class Napi::Function __cdecl Napi::ObjectWrap<
class CerberusPlayer>::DefineClass(class Napi::Env,char const *,unsigned __int64,struct napi_property_descriptor const *,void *)" (?DefineClass@?$ObjectWrap@VCerberusPl
ayer@@@Napi@@CA?AVFunction@2@VEnv@2@PEBD_KPEBUnapi_property_descriptor@@PEAX@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_create_function referenced in function "private: static class Napi::Function __cdecl Napi::ObjectWra
p<class CerberusPlayer>::DefineClass(class Napi::Env,char const *,unsigned __int64,struct napi_property_descriptor const *,void *)" (?DefineClass@?$ObjectWrap@VCerberus
Player@@@Napi@@CA?AVFunction@2@VEnv@2@PEBD_KPEBUnapi_property_descriptor@@PEAX@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_set_named_property referenced in function "public: void __cdecl Napi::Object::Set<class Napi::Functi
on>(char const *,class Napi::Function const &)" (??$Set@VFunction@Napi@@@Object@Napi@@QEAAXPEBDAEBVFunction@1@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcx
proj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_define_properties referenced in function "private: static class Napi::Function __cdecl Napi::ObjectW
rap<class CerberusPlayer>::DefineClass(class Napi::Env,char const *,unsigned __int64,struct napi_property_descriptor const *,void *)" (?DefineClass@?$ObjectWrap@VCerber
usPlayer@@@Napi@@CA?AVFunction@2@VEnv@2@PEBD_KPEBUnapi_property_descriptor@@PEAX@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_get_cb_info referenced in function "public: __cdecl Napi::CallbackInfo::CallbackInfo(struct napi_env
__ *,struct napi_callback_info__ *)" (??0CallbackInfo@Napi@@QEAA@PEAUnapi_env__@@PEAUnapi_callback_info__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxpro
j]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_get_new_target referenced in function "private: static struct napi_value__ * __cdecl Napi::ObjectWra
p<class CerberusPlayer>::ConstructorCallbackWrapper(struct napi_env__ *,struct napi_callback_info__ *)" (?ConstructorCallbackWrapper@?$ObjectWrap@VCerberusPlayer@@@Napi
@@CAPEAUnapi_value__@@PEAUnapi_env__@@PEAUnapi_callback_info__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_define_class referenced in function "private: static class Napi::Function __cdecl Napi::ObjectWrap<c
lass CerberusPlayer>::DefineClass(class Napi::Env,char const *,unsigned __int64,struct napi_property_descriptor const *,void *)" (?DefineClass@?$ObjectWrap@VCerberusPla
yer@@@Napi@@CA?AVFunction@2@VEnv@2@PEBD_KPEBUnapi_property_descriptor@@PEAX@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_wrap referenced in function "public: __cdecl CerberusPlayer::CerberusPlayer(class Napi::CallbackInfo
const &)" (??0CerberusPlayer@@QEAA@AEBVCallbackInfo@Napi@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_unwrap referenced in function "struct napi_value__ * __cdecl Napi::details::WrapCallback<class <lamb
da_04785c1abc4759ec667a151abddba1d6> >(class <lambda_04785c1abc4759ec667a151abddba1d6>)" (??$WrapCallback@V<lambda_04785c1abc4759ec667a151abddba1d6>@@@details@Napi@@YAP
EAUnapi_value__@@V<lambda_04785c1abc4759ec667a151abddba1d6>@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_create_external referenced in function "private: static class Napi::Function __cdecl Napi::ObjectWra
p<class CerberusPlayer>::DefineClass(class Napi::Env,char const *,unsigned __int64,struct napi_property_descriptor const *,void *)" (?DefineClass@?$ObjectWrap@VCerberus
Player@@@Napi@@CA?AVFunction@2@VEnv@2@PEBD_KPEBUnapi_property_descriptor@@PEAX@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol napi_throw_type_error referenced in function "private: static struct napi_value__ * __cdecl Napi::ObjectW
rap<class CerberusPlayer>::ConstructorCallbackWrapper(struct napi_env__ *,struct napi_callback_info__ *)" (?ConstructorCallbackWrapper@?$ObjectWrap@VCerberusPlayer@@@Na
pi@@CAPEAUnapi_value__@@PEAUnapi_env__@@PEAUnapi_callback_info__@@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
CerberusPlayer.obj : error LNK2019: unresolved external symbol "private: static class Napi::FunctionReference CerberusPlayer::constructor" (?constructor@CerberusPlayer@
@0VFunctionReference@Napi@@A) referenced in function "public: static class Napi::Object __cdecl CerberusPlayer::Init(class Napi::Env,class Napi::Object)" (?Init@Cerberu
sPlayer@@SA?AVObject@Napi@@VEnv@3@V23@@Z) [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj]
C:\Users\marcu\.cmake-js\electron-ia64\v5.0.3\node.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64' [C:\Users\marcu\Git\venobo
\cerberus\build\Cerberus.vcxproj]
C:\Users\marcu\Git\venobo\cerberus\build\Release\Cerberus.node : fatal error LNK1120: 32 unresolved externals [C:\Users\marcu\Git\venobo\cerberus\build\Cerberus.vcxproj
]
Hi @marcus-sa,
until now node-gyp is the de-facto standard build tool for Node.js addons. Could you try to add to your project a file binding.gyp
containing the configuration reported below and then add digit npm install
? What is the result that you obtain?
{
"targets": [
{
"target_name": "Cerberus",
"sources": [
"src/Cerberus.cpp",
"src/CerberusPlayer.cpp"
],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'include_dirs': [
"<!@(node -p \"require('node-addon-api').include\")"
],
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")"
],
'conditions': [
['OS=="win"', {
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1
}
}
}],
['OS=="mac"', {
"xcode_settings": {
"CLANG_CXX_LIBRARY": "libc++",
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
#'MACOSX_DEPLOYMENT_TARGET': '10.7'
}
}]
]
}
]
}
Hi @marcus-sa, is there some updates about your problem?
Hi @marcus-sa, I saw that you solved the problem, so I'm closing the issue, but please feels free to reopen it if you need.
Hi @marcus-sa, I tried to solve your problem, but I have only macOS and I only changed the CMake file like reported here. Essentially I replaced this part of your configuration:
# Include N-API wrappers execute_process(COMMAND node -p "require('node-addon-api').include" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE NODE_ADDON_API_DIR ) string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) target_include_directories(${PROJECT_NAME} PRIVATE ${NODE_ADDON_API_DIR})
with this:
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/node_modules/node-addon-api ${CMAKE_SOURCE_DIR}/node_modules/node-addon-api/src ${CMAKE_JS_INC}) target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_JS_LIB})
Furthermore I added this line at the begin of make file
set (CMAKE_CXX_STANDARD 11)
All worked good for me, could you try if my solution works for you?
Actually, the original CMake code clause (under # Include N-API wrappers
) is correct, the only missing part was adding ${CMAKE_JS_LIB}
to target_link_libraries
.
https://github.com/venobo/cerberus/issues/1