【发布时间】:2013-05-07 13:04:41
【问题描述】:
我有两个文件让我很伤心:camAVTEx.h 和 camAVTEx.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