【问题标题】:Unresolved external symbol, cannot figure out why未解析的外部符号,无法弄清楚原因
【发布时间】:2013-05-07 13:04:41
【问题描述】:

我有两个文件让我很伤心: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: 无法解析的外部符号 "public: __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

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

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

【问题讨论】:

  • 您确定该文件可以访问您程序中的包含文件吗?您的文件可能找不到那些包含/
  • 相当明显,但您确定 camAVTEx.cpp 已编译并链接到您的 otherfile.cpp 文件吗?你的构建系统是什么?
  • @Need4Sleep 我不明白它是如何无法访问的
  • 这是因为 CamAVTex.o 没有链接到您的可执行文件中。这与#include 文件无关。
  • @xcdemon05 - 这不是你三月份问的同一个问题吗???

标签: c++ object inheritance linker unresolved-external


【解决方案1】:

无论你怎么看,你遇到的错误: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 文件中看到了它的声明,但是哈拉斯,它可以't find (= resolve) 这个符号的实现(简称代码)。

发生这种情况通常有几个可能的原因:

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

【讨论】:

  • 我觉得我的问题可能是您的第二个要点。我对链接器设置还不是很好,知道如何在 VS2010 中执行此操作吗?
猜你喜欢
  • 1970-01-01
  • 2018-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-07
  • 1970-01-01
相关资源
最近更新 更多