简体   繁体   English

链接器错误LNK2019?

[英]Linker error LNK2019?

I have the following files 我有以下文件

file1_moduleA.hpp file1_moduleA.hpp

file1_moduleA.cpp file1_moduleA.cpp

sharedFile.hpp sharedFile.hpp

file1_moduleB.cpp 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");
}
//...

The following are in one Visual Studio Project, Project A: file1_moduleA.hpp, file1_moduleA.cpp and sharedFile.hpp 以下是一个Visual Studio项目Project A中的文件:file1_moduleA.hpp,file1_moduleA.cpp和sharedFile.hpp

The following are in another VS Project, Project B: file1_moduleB.cpp, file1_moduleB.hpp 以下是另一个VS项目B项目:file1_moduleB.cpp,file1_moduleB.hpp

Project A compiles and links perfectly, whereas Project B compiles but gives an unresolved symbol for CustomClass *doSomething(CustomClass *var1, const char *var2) at someFunction in file1_moduleB.cpp 项目A编译并完美链接,而项目B编译但在file1_moduleB.cpp中的someFunction上CustomClass * doSomething(CustomClass * var1,const char * var2)给出了一个未解析的符号

I have tried defining the function with and without extern; 我尝试过定义带有或不带有extern的函数; tried using a separate file for the template in file1_moduleA.hpp; 尝试对file1_moduleA.hpp中的模板使用单独的文件; tried inducing dependency between ProjectB and ProjectA in VS, but nothing seems to work. 试图在VS中引入ProjectB和ProjectA之间的依赖关系,但似乎没有任何效果。 I am unsure why the definition is not being found during linking. 我不确定为什么在链接期间找不到定义。 ProjectA.lib however, is being created. 但是,正在创建ProjectA.lib。

Any help in this regard would be appreciated. 在这方面的任何帮助将不胜感激。

if you are using visual studio, and these are different project, then make project B dependent upon project A. 如果您使用的是Visual Studio,而这些是不同的项目,则使项目B依赖于项目A。

Right click on the solution. 右键单击解决方案。 Go to project dependencies. 转到项目依赖项。

Choose Project B. 选择项目B。

Click Project A (making project B dependent upon Project A) 单击项目A(使项目B取决于项目A)

rebuild. 重建。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM