VS2012 node.js module: troubleshooting LNK2005/LNK1169 errors

I'm working on the node.js module in Visual Studio and have the following file structure:

load.h

#include <string>
#include <v8.h>

void property_guard(v8::Local<v8::Object> obj, v8::Local<v8::String> name, const std::string path);

load.cpp

#include "load.h"

void property_guard(v8::Local<v8::Object> obj, v8::Local<v8::String> name, const std::string path) {
    if (!obj->Has(name)) {
        throw path + " does not exist";
    }
}

main.cpp

#include <string>
#include <node.h>
#include <v8.h>
#include "load.h"

void integer_type_guard(v8::Local<v8::Value> obj, const std::string path) {
    if (!obj->IsInt32()) {
        throw path + " is not an integer";
    }
}

int get_int_property(v8::Local<v8::Object> obj, v8::Local<v8::String> name, const std::string path) {
    property_guard(obj, name, path);
    v8::Local<v8::Value> value = obj->Get(name);
    integer_type_guard(value, path);
    return value->Int32Value();
}

I expect that the structure is correct, but I get an error in Visual Studio and similar when I compile the project with node-gyp:

error LNK2005: "public: class v8::Object * __cdecl v8::Handle<class v8::Object>::operator->(void)const " (??C?$Handle@VObject@v8@@@v8@@QEBAPEAVObject@1@XZ) already defined in node.lib(node.exe)   C:\...\load.obj
error LNK1169: one or more multiply defined symbols found   C:\...\Test1.dll

Removing the node.h from the main.cpp includes removes the error (I need it to register the module). Moving the property_guard method to main.cpp also solves the issue.

What is the correct way of moving declaration to other file in this case?

My environment:

  • Visual Studio 2012
  • node.js 0.10.12 x64

Many thanks to Bert Belder from node.js mailing list for the solution. I need to add #include before including anything else in my .cpp files.