0

I developed two classes for running a camera frame grabber in a console app (one to grab the images and one to process them) and would now like to implement these classes into an MFC project. The class works fine in the console app. When I attempted to use them in the MFC app I get LNK2019 errors. Here's some code pieces, the image display class is written in a very similar way:

IMAQ class (for grabing images): 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
}

In my MFC dialog header file I include the IMAQClass.h header file which is sufficient for the console app to work correctly, yet, as I said above, the MFC app returns unresolved external symbol errors. MFC project seetings additional include directories includes the directory containing IMAQ header file.

Why am I receiving unresolved externals? Thanks

Error message as requested:

 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)

EDIT: Problem solved, but I guess I don't really understand why.

So the comments posted said that I needed to link to the library file. The two classes I was having a problem with do not generate .dll nor .lib files, just .obj. But on a whim I went back and included the .obj file to the link dependencies.

So now my question is: .obj files need to be linked like libraries if they are not generated along with the executable?

GregD
  • 195
  • 1
  • 2
  • 13
  • 2
    How about posting posting the exact error message, i.e., which symbols are undefined? Including a header is one thing, but if it is just the interface to a library you need to link that in as well under your linker settings. – Ed S. Apr 23 '12 at 21:58
  • Error messages added. The IMAQ and ImageDisplay classes do not generate library files. However do I need to some how link to the object files that they generate? – GregD Apr 23 '12 at 22:04
  • Yes, looks like you are not linking the code in your project. – Jonathan Wood Apr 23 '12 at 22:09
  • The code has to come from somewhere. If you have the sources in your project it creates the .obj files and knows they need to be included, but if all you have is the .obj it doesn't search them out - you have to include them in the project too. – Mark Ransom Apr 23 '12 at 22:27

1 Answers1

0

You haven't given us enough detail to help you. You have told us that you are getting a linker error, but you need to tell us the exact error message, i.e., which symbols are undefined?

Here is my guess; you have included an additional header file. This header file is part of a library, but you have not linked in the library itself, only included the header. So you got the first part right, now you need to open up your linker settings page, add the additional library directory (i.e., where the .lib, .obj, .whatever implementation file resides), and then add the name of the library to the "Additional Dependencies" section.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
  • Got it: I had to link the .obj file. I didn't know that such a linkage was necessary. – GregD Apr 23 '12 at 22:12
  • @GregD: The linker has to have access to the definition(s) *somewhere*, the header files are not enough. – Ed S. Apr 23 '12 at 23:00