链接器错误已经定义

时间:2013-09-23 11:27:27

标签: c++ visual-studio-2010 node.js debugging linker-errors

我正在创建一个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中使用,Arguments::Length()中使用communicator.cc。即使这样,所有错误都会引用communicator.cc

我只调用cc文件中的函数而不给出任何新的定义。

有什么问题?

提前致谢。

1 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,我找到了解决方案here。 放一个#include&lt; node.h&gt;在每个#include&lt; v8.h&gt;之前。