0

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

4

1 回答 1

0

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

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

于 2012-04-23T22:06:30.553 回答