LNK 2019在MFC中使用自定义类时出错

时间:2012-04-23 21:51:09

标签: c++ class mfc lnk2019

我开发了两个类,用于在控制台应用程序中运行相机图像采集器(一个用于获取图像,一个用于处理它们),现在想要将这些类实现到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文件需要像库一样链接,如果它们不与可执行文件一起生成?

1 个答案:

答案 0 :(得分:0)

您没有给我们足够的细节来帮助您。您告诉我们您收到链接器错误,但是您需要告诉我们确切的错误消息,即哪些符号未定义?

这是我的猜测;你已经包含了一个额外的头文件。此头文件是库的一部分,但您没有在库本身中链接,只包含头。所以你得到了第一部分,现在你需要打开链接器设置页面,添加额外的库目录(即.lib,.obj,.whatever实现文件所在的位置),然后添加库的名称到“附加依赖”部分。