2013-07-03 36 views
2

我工作在Visual Studio中的Node.js模塊,並具有以下文件結構:VS2012的Node.js模塊:故障排除LNK2005/LNK1169錯誤

load.h

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

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

負荷。 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(); 
} 

我期望結構是正確的,但我得到的Visual Studio和類似的錯誤,當我編譯節點GYP項目:

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

從main.cpp中包括去除node.h刪除錯誤(我需要它來註冊模塊)。將property_guard方法移至main.cpp也解決了這個問題。

在這種情況下將聲明移動到其他文件的正確方法是什麼?

我的環境:

  • 的Visual Studio 2012
  • node.js的0.10.12 64

回答

1

從爲solution node.js的郵件列表非常感謝伯特Belder。在包含我的.cpp文件中的其他內容之前,我需要添加#include。