0

我有两个文件让我很伤心:camAVTEx.hcamAVTEx.cpp. 这是两个文件的一般设置:


//.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
}

然后,在不同目录中的文件中,我对 .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();
}

当我编译时,我收到以下错误:

8>otherfile.obj:错误 LNK2001:未解析的外部符号“公共:__cdecl camera_avtcam_ex_t::camera_avtcam_ex_t(void)”(??0camera_avtcam_ex_t@@QEAA@XZ)

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

8>....\bin\x64\Release\otherfile.exe : 致命错误 LNK1120: 2 unresolved externals

我一生都无法弄清楚为什么它找不到这两个功能的实现。

所以我想我的问题很明显:为什么我会收到这些错误,我需要改变什么来修复它们?

4

1 回答 1

0

无论您如何看待它,您遇到的错误: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文件中看到了它的声明,但是哈拉斯,它找不到(= 解析)这个符号的实现(简而言之,代码)。

这通常是由于几个可能的原因而发生的:

  • 您没有告诉编译器您尝试使用的代码(.cpp),所以他不知道。尝试将文件添加到您的项目中。
  • 您编译缺少的代码,但不要与它链接。检查您是否没有两个单独的项目,或者如果它来自一个库,请尝试将库添加到您的项目中。
  • 在某种程度上,编译后的代码与其定义不匹配(在混合 C 和 C++ 或混淆命名空间时发生)检查您是否没有声明相互矛盾的封闭命名空间。
  • (也许其他原因我不知道?)
于 2013-05-15T09:24:42.523 回答