我正在制作一个nodejs插件。我的 Visual Studio 项目中有 5 个文件:
comm.h/cc, node_main.cc, util.h/cc
我将它与图书馆链接node.lib
node_main.cc有一个功能:
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))));
}
当我构建解决方案时,我收到以下链接器错误:
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
and Arguments::Length()
用于communicator.cc
。即使如此,所有错误都指的是communicator.cc
.
我只是调用 cc 文件中的函数,没有给出任何新的定义。
问题是什么 ?
提前致谢。
我遇到了同样的问题,我找到了解决方案here https://groups.google.com/forum/#!topic/nodejs/onA0S01INtw。
在每个#include 之前放置一个#include 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)