【问题标题】:Linker Errors Already defined链接器错误已定义
【发布时间】:2013-09-23 11:27:27
【问题描述】:

我正在制作一个 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.ccArguments::Length()用于communicator.cc。即便如此,所有错误都指向communicator.cc

我只是调用 cc 文件中的函数,没有给出任何新定义。

有什么问题?

提前致谢。

【问题讨论】:

  • 您是否将一个 .cc 文件包含在另一个文件中?
  • @john 不,我没有在我的项目中的任何地方包含 .cc 文件。
  • 也许您是在头文件中定义这些函数而不是说它们是内联的?只有少数几件事会导致此错误,但无法查看所有代码并查看项目的设置方式,很难说出问题所在。不管是什么,都没有什么复杂的,只是在您编写代码或创建项目时出现了一些基本错误。

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


【解决方案1】:

我遇到了同样的问题,我找到了解决方案here。 在每个#include 之前放置一个#include

【讨论】:

    猜你喜欢
    • 2012-10-06
    • 2022-01-13
    • 2016-03-09
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    相关资源
    最近更新 更多