简体   繁体   English

无法解析的外部符号,无法找出原因

[英]Unresolved external symbol, cannot figure out why

I have two files that are causing me a lot of grief: camAVTEx.h and camAVTEx.cpp . 我有两个文件让我很伤心: camAVTEx.hcamAVTEx.cpp Here is the general setup for the two files: 这是两个文件的常规设置:


//.h////////////////////////////////////////////////

/*
#includes to some other files
*/

class camera_avtcam_ex_t : public camera_t
{
public:
    camera_avtcam_ex_t();
    virtual ~camera_avtcam_ex_t();

private:
    //some members

public:
    //some methods

};

void GlobalShutdownVimbaSystem();

//.cpp/////////////////////////////////////////////

#include "StdAfx.h"
#include "camAVTEx.h"

//some other #includes

camera_avtcam_ex_t::camera_avtcam_ex_t()
{
}

//rest of the class' functions

void GlobalShutdownVimbaSystem()
{
    //implememtation
}

Then, in a file in a different directory, I do a #include to the exact location of the .h file and try to use the class: 然后,在另一个目录中的文件中,对.h文件的确切位置执行#include并尝试使用该类:


//otherfile.cpp

#include "..\..\src\HardSupport\Camera.h"
//this is the base camera class (camera_t)

#include "..\..\src\HardControl\camAVTEx.h" 
//this is indeed where both the .h and .cpp files are located

void InitCam
{
    camera_t* maincam = new camera_avtcam_ex_t();
}

void OnExit()
{
    GlobalShutdownVimbaSystem();
}

When I compile, I get the following errors: 编译时,出现以下错误:

8>otherfile.obj : error LNK2001: unresolved external symbol "public: __cdecl camera_avtcam_ex_t::camera_avtcam_ex_t(void)" (??0camera_avtcam_ex_t@@QEAA@XZ) 8> otherfile.obj:错误LNK2001:未解决的外部符号“ public:__cdecl camera_avtcam_ex_t :: camera_avtcam_ex_t(void)”(?? 0camera_avtcam_ex_t @@ QEAA @ XZ)

8>otherfile.obj : error LNK2001: unresolved external symbol "void __cdecl GlobalShutdownVimbaSystem(void)" (?GlobalShutdownVimbaSystem@@YAXXZ) 8> otherfile.obj:错误LNK2001:无法解析的外部符号“ void __cdecl GlobalShutdownVimbaSystem(void)”(?GlobalShutdownVimbaSystem @@ YAXXZ)

8>....\\bin\\x64\\Release\\otherfile.exe : fatal error LNK1120: 2 unresolved externals 8> .... \\ bin \\ x64 \\ Release \\ otherfile.exe:致命错误LNK1120:2个未解析的外部组件

I cannot for the life of me figure out why it can't find the implementations for these two functions. 我一生无法弄清为什么找不到这两个功能的实现。

So I guess my question is fairly obvious: Why am I getting these errors and what do I need to change to fix them? 因此,我想我的问题很明显:为什么会出现这些错误?需要进行哪些更改以解决这些错误?

Whatever how you look at it, the error you have : unresolved external symbol "public: __cdecl camera_avtcam_ex_t::camera_avtcam_ex_t(void)" (??0camera_avtcam_ex_t@@QEAA@XZ) means that the compiler knows the symbol camera_avtcam_ex_t::camera_avtcam_ex_ (that's the class constructor) since he saw its declaration in the camAVTEx.h file but halas, it can't find (= resolve) the implementation of this symbol (in short, the code). 无论您如何看待,您都将遇到以下错误: unresolved external symbol "public: __cdecl camera_avtcam_ex_t::camera_avtcam_ex_t(void)" (??0camera_avtcam_ex_t@@QEAA@XZ)表示编译器知道符号camera_avtcam_ex_t::camera_avtcam_ex_ )类构造函数),因为他在camAVTEx.h文件中看到了它的声明,但是哈拉,它找不到(=解决)该符号的实现(简而言之,代码)。

This usually happen because of several possible causes : 通常由于几种可能的原因而发生这种情况:

  • you didn't tell the compiler about the code (.cpp) you try to use so he doesn't know it. 您没有告诉编译器您尝试使用的代码(.cpp),因此他不知道。 Try to add the file to your project. 尝试将文件添加到您的项目。
  • you compile the missing code, but don't link with it. 您编译缺少的代码,但不要链接它。 Check if you don't have two separated projects or try to add the lib to your project if it comes from a lib. 检查您是否没有两个分离的项目,或者如果该库来自某个库,则尝试将其添加到您的项目中。
  • in some way, the compiled code does not match its definition (happens when mixing C and C++ or messing with namespaces) Check if you are not declaring contradicting enclosing namespaces. 在某种程度上,编译后的代码与它的定义不匹配(在混合使用C和C ++或将名称空间弄乱时发生),检查是否没有声明矛盾的封闭名称空间。
  • (maybe other reasons I don't know ?) (也许是我不知道的其他原因?)

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

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