我開發了兩個類,用於在控制檯應用程序(一個用於獲取圖像,一個用於處理它們)中運行攝像頭圖像採集卡,現在想要將這些類實現到MFC項目中。該類在控制檯應用程序中正常工作。當我嘗試在MFC應用程序中使用它們時,我收到了LNK2019錯誤。下面是一些代碼片段,圖像顯示類是寫在一個非常相似的方式:LNK 2019在MFC中使用自定義類時出錯
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)" ([email protected]@[email protected]) referenced in function "public: virtual __thiscall CuOCTMFCAppDlg::~CuOCTMFCAppDlg(void)" ([email protected]@[email protected])
1>uOCT MFC AppDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall IMAQ::~IMAQ(void)" ([email protected]@[email protected])
1>uOCT MFC App.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall ImgDspClass::~ImgDspClass(void)" ([email protected]@[email protected]) referenced in function "public: virtual __thiscall CuOCTMFCAppDlg::~CuOCTMFCAppDlg(void)" ([email protected]@[email protected])
1>uOCT MFC AppDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall ImgDspClass::~ImgDspClass(void)" ([email protected]@[email protected])
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall ImgDspClass::ImgDspClass(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall CuOCTMFCAppDlg::CuOCTMFCAppDlg(class CWnd *)" ([email protected]@[email protected]@@@Z)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: __thiscall IMAQ::IMAQ(void)" ([email protected]@[email protected]) referenced in function "public: __thiscall CuOCTMFCAppDlg::CuOCTMFCAppDlg(class CWnd *)" ([email protected]@[email protected]@@@Z)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: int __thiscall ImgDspClass::SetReferencePath(char * const)" ([email protected]@@[email protected]) referenced in function "protected: virtual int __thiscall CuOCTMFCAppDlg::OnInitDialog(void)" ([email protected]@@MAEHXZ)
1>uOCT MFC AppDlg.obj : error LNK2019: unresolved external symbol "public: int __thiscall IMAQ::SetFilePath(char * const)" ([email protected]@@[email protected]) referenced in function "protected: virtual int __thiscall CuOCTMFCAppDlg::OnInitDialog(void)" ([email protected]@@MAEHXZ)
編輯:問題解決了,但我想我真的不明白爲什麼。
所以發佈的評論說我需要鏈接到庫文件。我遇到問題的兩個類別不生成.dll和.lib文件,只是.obj。但一時興起,我回去並將.obj文件包含到鏈接依賴項中。
所以現在我的問題是:.obj文件需要像庫一樣鏈接,如果它們不與可執行文件一起生成的話?
如何發佈發佈確切的錯誤消息,即哪些符號未定義?包含頭文件是一回事,但如果它只是庫的接口,則需要在鏈接器設置下鏈接它。 – 2012-04-23 21:58:23
添加了錯誤消息。 IMAQ和ImageDisplay類不會生成庫文件。但是,我需要如何鏈接到它們生成的對象文件? – GregD 2012-04-23 22:04:58
是的,看起來你沒有鏈接你的項目中的代碼。 – 2012-04-23 22:09:05