pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
886 stars 118 forks source link

Definition found in both static library and header file. Results in linker error. #203

Closed nikovacs closed 7 months ago

nikovacs commented 7 months ago

I am attempting to use v8pp as a static library just to use the context object, as it makes it much easier for exposing classes, autowrapping them, etc. I was able to build the lib in not header-only mode. However, now when I try to build, I am getting linker errors (below). I suspect that it is because definitions are being found in both the lib and the header file.

Perhaps I am building it incorrectly...

The following are the errors that are being generated at build time in my own project.

1>v8pp.lib(class.obj) : error LNK2005: "public: __cdecl v8pp::detail::class_info::class_info(class v8pp::detail::type_info const &,class v8pp::detail::type_info const &)" (??0class_info@detail@v8pp@@QEAA@AEBVtype_info@12@0@Z) already defined in ClientScriptLoader.obj
1>v8pp.lib(class.obj) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl v8pp::detail::class_info::class_name(void)const " (?class_name@class_info@detail@v8pp@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in ClientScriptLoader.obj
1>v8pp.lib(class.obj) : error LNK2005: "private: class std::_Vector_iterator<class std::_Vector_val<struct std::_Simple_types<class std::unique_ptr<struct v8pp::detail::class_info,struct std::default_delete<struct v8pp::detail::class_info> > > > > __cdecl v8pp::detail::classes::find(class v8pp::detail::type_info const &)" (?find@classes@detail@v8pp@@AEAA?AV?$_Vector_iterator@V?$_Vector_val@U?$_Simple_types@V?$unique_ptr@Uclass_info@detail@v8pp@@U?$default_delete@Uclass_info@detail@v8pp@@@std@@@std@@@std@@@std@@@std@@AEBVtype_info@23@@Z) already defined in ClientScriptLoader.obj
1>v8pp.lib(class.obj) : error LNK2005: "private: static class v8pp::detail::classes * __cdecl v8pp::detail::classes::instance(enum v8pp::detail::classes::operation,class v8::Isolate *)" (?instance@classes@detail@v8pp@@CAPEAV123@W4operation@123@PEAVIsolate@v8@@@Z) already defined in ClientScriptLoader.obj
1>Core.lib(ScriptLoader.obj) : error LNK2005: "void __cdecl v8pp::cleanup(class v8::Isolate *)" (?cleanup@v8pp@@YAXPEAVIsolate@v8@@@Z) already defined in v8pp.lib(class.obj)
1>Core.lib(ScriptLoader.obj) : error LNK2005: "public: static void __cdecl v8pp::detail::classes::remove_all(class v8::Isolate *)" (?remove_all@classes@detail@v8pp@@SAXPEAVIsolate@v8@@@Z) already defined in v8pp.lib(class.obj)
1>W:\VSSource\repos\Project\x64\Debug\Client.exe : fatal error LNK1169: one or more multiply defined symbols found

The error occurs as soon as I try to add the module to the context using v8pp::context::module. If I try to add the module a different way (below, snippet from my ClientScriptLoader class referenced in the errors above), it builds and does not result in that error. I would prefer to use the module method on the context due to its cleaner syntax and also because I am trying to create more complex classes and modules once I get this basic one to work.

//_isolate->GetCurrentContext()->Global()->Set(_isolate->GetCurrentContext(), v8pp::to_v8(_isolate, "clientPlayer"), clientPlayer.new_instance());
ctx->module("clientPlayer", clientPlayer);