puerts/backend-nodejs

node-20.x静态库vs2022下编译后的使用问题

Opened this issue · 4 comments

系统:win11
nodejs:20.x
编译命令:.\vcbuild.bat debug nonpm static openssl-no-asm vs2022 dll
问题描述:
静态库libnode编译成功,然后新建项目将test\embedding\embedtest.cc的代码复制到vs新建的其他项目运行结果报错:
错误信息:
微信图片_20240708142924

c++新手求问,不胜感激

1>main.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl node::EmbedderSnapshotData::DeleteSnapshotData::operator()(class node::EmbedderSnapshotData const *)const " (??RDeleteSnapshotData@EmbedderSnapshotData@node@@QEBAXPEBV12@@z),函数 "public: __cdecl std::unique_ptr<class node::EmbedderSnapshotData const ,struct node::EmbedderSnapshotData::DeleteSnapshotData>::~unique_ptr<class node::EmbedderSnapshotData const ,struct node::EmbedderSnapshotData::DeleteSnapshotData>(void)" (??1?$unique_ptr@$$CBVEmbedderSnapshotData@node@@UDeleteSnapshotData@12@@std@@qeaa@XZ) 中引用了该符号
1>main.obj : error LNK2019: 无法解析的外部符号 "public: static class std::unique_ptr<class node::EmbedderSnapshotData const ,struct node::EmbedderSnapshotData::DeleteSnapshotData> __cdecl node::EmbedderSnapshotData::FromFile(struct _iobuf *)" (?FromFile@EmbedderSnapshotData@node@@sa?AV?$unique_ptr@$$CBVEmbedderSnapshotData@node@@UDeleteSnapshotData@12@@std@@PEAU_iobuf@@@z),函数 "int __cdecl RunNodeInstance(class node::MultiIsolatePlatform *,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &)" (?RunNodeInstance@@YAHPEAVMultiIsolatePlatform@node@@aebv?$vector@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@v?$allocator@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@2@@std@@1@Z) 中引用了该符号
1>main.obj : error LNK2019: 无法解析的外部符号 "public: static class std::unique_ptr<class node::EmbedderSnapshotData const ,struct node::EmbedderSnapshotData::DeleteSnapshotData> __cdecl node::EmbedderSnapshotData::FromBlob(class std::vector<char,class std::allocator > const &)" (?FromBlob@EmbedderSnapshotData@node@@sa?AV?$unique_ptr@$$CBVEmbedderSnapshotData@node@@UDeleteSnapshotData@12@@std@@aebv?$vector@DV?$allocator@D@std@@@4@@z),函数 "int __cdecl RunNodeInstance(class node::MultiIsolatePlatform *,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &)" (?RunNodeInstance@@YAHPEAVMultiIsolatePlatform@node@@aebv?$vector@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@v?$allocator@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@2@@std@@1@Z) 中引用了该符号
1>main.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl node::EmbedderSnapshotData::ToFile(struct _iobuf *)const " (?ToFile@EmbedderSnapshotData@node@@QEBAXPEAU_iobuf@@@z),函数 "int __cdecl RunNodeInstance(class node::MultiIsolatePlatform *,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &)" (?RunNodeInstance@@YAHPEAVMultiIsolatePlatform@node@@aebv?$vector@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@v?$allocator@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@2@@std@@1@Z) 中引用了该符号
1>main.obj : error LNK2019: 无法解析的外部符号 "public: class std::vector<char,class std::allocator > __cdecl node::EmbedderSnapshotData::ToBlob(void)const " (?ToBlob@EmbedderSnapshotData@node@@qeba?AV?$vector@DV?$allocator@D@std@@@std@@xz),函数 "int __cdecl RunNodeInstance(class node::MultiIsolatePlatform *,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &,class std::vector<class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::allocator<class std::basic_string<char,struct std::char_traits,class std::allocator > > > const &)" (?RunNodeInstance@@YAHPEAVMultiIsolatePlatform@node@@aebv?$vector@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@v?$allocator@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@2@@std@@1@Z) 中引用了该符号

可以尝试找下看哪个文件有这些符号,看它编译到那个库。

不过最终搞不通也是常态,嵌入式方式不是nodejs的常规使用方式,我之前也是一个个版本的找到能使用的版本。而且还可能需要一些小修改满足各平台的编译。

node 不支持2022,只能用2019。 @trising