我开发了两个类用于在控制台应用程序中运行相机图像采集卡(一个用于抓取图像,一个用于处理图像),现在想将这些类实现到 MFC 项目中。该类在控制台应用程序中运行良好。当我尝试在 MFC 应用程序中使用它们时,我收到 LNK2019 错误。这是一些代码片段,图像显示类的编写方式非常相似:
IMAQ 类(用于抓取图像):IMAQ.h:
#pragma once
#include <queue>
#include <fstream>
#include "CircularInterface.h"
... // some more includes
class IMAQ
{
public:
explicit IMAQ();
virtual ~IMAQ();
int SetupAcq(pRTCaptureStruc pRTCaptStruc);
... // some more functions
// The image acquisition thread
UINT ImgAcqThread(LPVOID lpdwParam);
private:
BFU32 BdNum,
BdInitOptns,
NumBuffers,
CircInitOptions;
// image acquisition parameters
BFU32 ImageSize,
BitDepth,
Xsize,
Ysize,
NumPixels,
BytesPerPix;
bool GetFrame;
... // some more private members
}; // class IMAQ
IMAQ.cpp:
#include "..\\Include\\IMAQClass.h"
IMAQ::IMAQ()
{
BdNum = 0;
BdInitOptns = CiSysInitialize;
CircInitOptions = BiAqEngJ;
NumBuffers = 4;
FilePath = NULL;
_isClean = true;
}
IMAQ::~IMAQ()
{
// Empty destructor
}
int IMAQ::SetupAcq(pRTCaptureStruc pRTCaptStruc)
{
...// left out code for brevity
}
... // some more functions, all functions declared in header file are defined.
uOCT MFC AppDlg.h:
#pragma once
#include "ImgDspClass.h"
#include "IMAQClass.h"
#include "afxwin.h"
// CuOCTMFCAppDlg dialog
class CuOCTMFCAppDlg : public CDialogEx
{
public:
HBITMAP hBmpWellA6;
BITMAP BmpWellA6;
UINT8 *pBitsWellA6;
BITMAPINFOHEADER bmpInfo;
IMAQ ImgAcq;
ImgDspClass ImgDsp;
char *LUTpath;
char FileName[FILENAME_MAX];
... // more members
};
uOCT MFC AppDlg.cpp:
#include "stdafx.h"
#include "uOCT MFC App.h"
#include "uOCT MFC AppDlg.h"
#include "afxdialogex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
BOOL CuOCTMFCAppDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// Change the file path here to change save location
ImgAcq.SetFilePath("C:\\Users\\uOCT clone\\Documents\\temporary\\test.dat");
ImgDsp.SetReferencePath("C:\\Users\\uOCT clone\\Documents\\temporary\\ref.dat");
return TRUE; // return TRUE unless you set the focus to a control
}
在我的 MFC 对话框头文件中,我包含 IMAQClass.h 头文件,它足以让控制台应用程序正常工作,但是,正如我上面所说,MFC 应用程序返回未解决的外部符号错误。MFC 项目additional include directories
设置包括包含 IMAQ 头文件的目录。
为什么我会收到未解决的外部问题?谢谢
请求的错误消息:
1>uOCT MFC App.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall IMAQ::~IMAQ(void)" (??1IMAQ@@UAE@XZ) referenced in function "public: virtual __thiscall CuOCTMFCAppDlg::~CuOCTMFCAppDlg(void)" (??1CuOCTMFCAppDlg@@UAE@XZ)
1>uOCT MFC AppDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall IMAQ::~IMAQ(void)" (??1IMAQ@@UAE@XZ)
1>uOCT MFC App.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall ImgDspClass::~ImgDspClass(void)" (??1ImgDspClass@@UAE@XZ) referenced in function "public: virtual __thiscall CuOCTMFCAppDlg::~CuOCTMFCAppDlg(void)" (??1CuOCTMFCAppDlg@@UAE@XZ)
1>uOCT MFC AppDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall ImgDspClass::~ImgDspClass(void)" (??1ImgDspClass@@UAE@XZ)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall ImgDspClass::ImgDspClass(void)" (??0ImgDspClass@@QAE@XZ) referenced in function "public: __thiscall CuOCTMFCAppDlg::CuOCTMFCAppDlg(class CWnd *)" (??0CuOCTMFCAppDlg@@QAE@PAVCWnd@@@Z)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall IMAQ::IMAQ(void)" (??0IMAQ@@QAE@XZ) referenced in function "public: __thiscall CuOCTMFCAppDlg::CuOCTMFCAppDlg(class CWnd *)" (??0CuOCTMFCAppDlg@@QAE@PAVCWnd@@@Z)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: int __thiscall ImgDspClass::SetReferencePath(char * const)" (?SetReferencePath@ImgDspClass@@QAEHQAD@Z) referenced in function "protected: virtual int __thiscall CuOCTMFCAppDlg::OnInitDialog(void)" (?OnInitDialog@CuOCTMFCAppDlg@@MAEHXZ)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: int __thiscall IMAQ::SetFilePath(char * const)" (?SetFilePath@IMAQ@@QAEHQAD@Z) referenced in function "protected: virtual int __thiscall CuOCTMFCAppDlg::OnInitDialog(void)" (?OnInitDialog@CuOCTMFCAppDlg@@MAEHXZ)
编辑:问题解决了,但我想我真的不明白为什么。
所以发布的评论说我需要链接到库文件。我遇到问题的两个类既不生成 .dll 也不生成 .lib 文件,只生成 .obj。但是一时兴起,我回去并将 .obj 文件包含到链接依赖项中。
所以现在我的问题是:如果 .obj 文件没有与可执行文件一起生成,它们是否需要像库一样链接?