Linker Errors Already Defined

I am doing addjs nodejs. I have 5 files in my visual studio project:

comm.h/cc, node_main.cc, util.h/cc

I link it to the library node.lib

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 create a solution, I get the 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

The function is IsString(), Arguments::[] and GetIsolate()used only in hello.cc, but Arguments::Length()used in communicator.cc. Even then, all errors relate to communicator.cc.

I only name functions in cc files without giving any new definition.

What is the problem?

Thanks in advance.

+3
source share
1 answer

, . #include < node.h > #include < v8.h > .

+3

Source: https://habr.com/ru/post/1681577/


All Articles