簡體   English   中英

鏈接器錯誤LNK2019?

[英]Linker error LNK2019?

我有以下文件

file1_moduleA.hpp

file1_moduleA.cpp

sharedFile.hpp

file1_moduleB.cpp

//sharedFile.hpp
extern CustomClass *doSomething(CustomClass *var1, const char *var2);
extern CustomClass *doSomethingElse(const char *var1);

template <class MYCLASS_A>
void myFunction(CustomClass *var1, const char* var2){
assert(somthing);
if (condition){
    new (MYCLASS_A);
}
}



//file1_moduleA.cpp
#include "sharedFile.hpp"
// Contains the definitions of doSomething and doSomethingElse among others


//file1_moduleA.hpp
// Other declarations


//file1_moduleB.cpp
#include"sharedFile.hpp"

//...SNIPPETS OF CODE
void someFunction(CustomClass* var1){
doSomething(var1, "FOO");
}
//...

以下是一個Visual Studio項目Project A中的文件:file1_moduleA.hpp,file1_moduleA.cpp和sharedFile.hpp

以下是另一個VS項目B項目:file1_moduleB.cpp,file1_moduleB.hpp

項目A編譯並完美鏈接,而項目B編譯但在file1_moduleB.cpp中的someFunction上CustomClass * doSomething(CustomClass * var1,const char * var2)給出了一個未解析的符號

我嘗試過定義帶有或不帶有extern的函數; 嘗試對file1_moduleA.hpp中的模板使用單獨的文件; 試圖在VS中引入ProjectB和ProjectA之間的依賴關系,但似乎沒有任何效果。 我不確定為什么在鏈接期間找不到定義。 但是,正在創建ProjectA.lib。

在這方面的任何幫助將不勝感激。

如果您使用的是Visual Studio,而這些是不同的項目,則使項目B依賴於項目A。

右鍵單擊解決方案。 轉到項目依賴項。

選擇項目B。

單擊項目A(使項目B取決於項目A)

重建。

您是否在項目B中包含共享文件?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM