已定义链接器错误 [英] Linker Errors Already defined
问题描述
我正在制作一个nodejs插件.我的Visual Studio项目中有5个文件:
I am making a nodejs addon. I have 5 files in my visual studio project :
comm.h/cc, node_main.cc, util.h/cc
我将其链接到库node.lib
node_main.cc具有一个功能:
node_main.cc has a function :
v8::Handle<v8::Value> StartMethod(const v8::Arguments &args) {
v8::HandleScope scope(args.GetIsolate()); // node_isolate
int length = args.Length();
std::vector<std::unique_ptr<char[]>> argv;
for(int i=0;i<length;++i) {
if(args[i]->IsString()) {
v8::String::Utf8Value str(args[i]);
const int strLen = ToCStringLen(str);
if(strLen) {
std::unique_ptr<char []> data(new char[strLen+1]);
strcpy_s(data.get(), strLen+1, ToCString(str));
argv.push_back(std::move(data));
}
}
}
return scope.Close(v8::Int32::New(MainMethod(argv.size(), &(argv[0]._Myptr))));
}
构建解决方案时,出现以下链接器错误:
When i build the solution i get following linker errors:
1>node.lib(node.exe) : error LNK2005: "public: bool __thiscall v8::Value::IsString(void)const " (?IsString@Value@v8@@QBE_NXZ) already defined in communicator.obj
1>node.lib(node.exe) : error LNK2005: "public: class v8::Local<class v8::Value> __thiscall v8::Arguments::operator[](int)const " (??AArguments@v8@@QBE?AV?$Local@VValue@v8@@@1@H@Z) already defined in communicator.obj
1>node.lib(node.exe) : error LNK2005: "public: int __thiscall v8::Arguments::Length(void)const " (?Length@Arguments@v8@@QBEHXZ) already defined in communicator.obj
1>node.lib(node.exe) : error LNK2005: "public: class v8::Isolate * __thiscall v8::Arguments::GetIsolate(void)const " (?GetIsolate@Arguments@v8@@QBEPAVIsolate@2@XZ) already defined in communicator.obj
功能IsString(), Arguments::[] and GetIsolate()
仅在hello.cc
中使用,而Arguments::Length()
在communicator.cc
中使用.即便如此,所有错误均参考communicator.cc
.
The function IsString(), Arguments::[] and GetIsolate()
is used only in hello.cc
and Arguments::Length()
are used in communicator.cc
. Even then all errors refer to communicator.cc
.
我只调用cc文件中的函数,没有给出任何新定义.
I am only calling the functions in cc files not giving any new definition.
出什么问题了?
提前谢谢.
推荐答案
I had the same problem, I found a solution here. Put an #include <node.h> before every #include <v8.h>.
这篇关于已定义链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!