VS2012 node.js模块:排除LNK2005/LNK1169错误
VS2012 node.js module: troubleshooting LNK2005/LNK1169 errors
我正在Visual Studio中开发node.js模块,具有以下文件结构:
负载.h
#include <string>
#include <v8.h>
void property_guard(v8::Local<v8::Object> obj, v8::Local<v8::String> name, const std::string path);
加载.cpp
#include "load.h"
void property_guard(v8::Local<v8::Object> obj, v8::Local<v8::String> name, const std::string path) {
if (!obj->Has(name)) {
throw path + " does not exist";
}
}
main.cpp
#include <string>
#include <node.h>
#include <v8.h>
#include "load.h"
void integer_type_guard(v8::Local<v8::Value> obj, const std::string path) {
if (!obj->IsInt32()) {
throw path + " is not an integer";
}
}
int get_int_property(v8::Local<v8::Object> obj, v8::Local<v8::String> name, const std::string path) {
property_guard(obj, name, path);
v8::Local<v8::Value> value = obj->Get(name);
integer_type_guard(value, path);
return value->Int32Value();
}
我希望结构是正确的,但当我用node-gyp:编译项目时,我在Visual Studio中遇到了一个类似的错误:
error LNK2005: "public: class v8::Object * __cdecl v8::Handle<class v8::Object>::operator->(void)const " (??C?$Handle@VObject@v8@@@v8@@QEBAPEAVObject@1@XZ) already defined in node.lib(node.exe) C:...load.obj
error LNK1169: one or more multiply defined symbols found C:...Test1.dll
从main.cpp中删除node.h包括删除错误(我需要它来注册模块)。将property_guard方法移到main.cpp也解决了这个问题。
在这种情况下,将声明移动到其他文件的正确方法是什么?
我的环境:
- Visual Studio 2012
- node.js 0.10.12 x64
非常感谢node.js邮件列表中的Bert Belder提供的解决方案。在.cpp文件中包含任何其他内容之前,我需要添加#include。
相关文章:
- 运行 C++ 单元测试时LNK2005链接错误
- 无法使函数公开。获取:"LNK2005"错误。如何调试链接器错误
- 如果两个静态库使用相同的另一个静态库,如何避免"LNK2005 Already Defined error"?
- 错误LNK2005无法解决问题的解决方案
- 在UE4(虚幻引擎4)中集成LuaJit时LNK2005错误
- 从模板继承的 MSVC DLL 导出类会导致LNK2005已定义的错误
- C++错误LNK2005和不同项目文件的常规继承
- LNK2005 中已经定义的函数
- LNK2005 AND LNK1169 Errors - C++
- 我需要帮助C LNK2005和LNK1169中的类代码分开
- 使用 AMD 的 Vulkan 内存分配器时出现链接器错误 (LNK2005)
- 我在用c ++编程时一直遇到LNK2005错误,我似乎无法弄清楚问题是什么
- 致命错误LNK1169:在C++Visual Studio中编写战舰游戏时发现的一个或多个多重定义的符号
- Error LNK2005 and LNK1169
- 找到一个或多个乘法定义的符号LNK1169错误
- LNK2005 of death (c++)
- 链接器错误LNK1169和LNK2005
- C++ 错误LNK2005和错误LNK1169
- VS2012 node.js模块:排除LNK2005/LNK1169错误
- LNK1169 and LNK2005 Errors