Note that there are some explanatory texts on larger screens.

plurals
  1. POLNK 2019 Error using custom class in MFC
    primarykey
    data
    text
    <p>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:</p> <p>IMAQ class (for grabing images): IMAQ.h:</p> <pre><code>#pragma once #include &lt;queue&gt; #include &lt;fstream&gt; #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 </code></pre> <p>IMAQ.cpp:</p> <pre><code>#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. </code></pre> <p>uOCT MFC AppDlg.h:</p> <pre><code>#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 }; </code></pre> <p>uOCT MFC AppDlg.cpp:</p> <pre><code>#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 &amp; 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX &lt; 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu-&gt;AppendMenu(MF_SEPARATOR); pSysMenu-&gt;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 } </code></pre> <p>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 <code>additional include directories</code> includes the directory containing IMAQ header file. </p> <p>Why am I receiving unresolved externals? Thanks</p> <p>Error message as requested:</p> <pre><code> 1&gt;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&gt;uOCT MFC AppDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall IMAQ::~IMAQ(void)" (??1IMAQ@@UAE@XZ) 1&gt;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&gt;uOCT MFC AppDlg.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall ImgDspClass::~ImgDspClass(void)" (??1ImgDspClass@@UAE@XZ) 1&gt;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&gt;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&gt;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&gt;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) </code></pre> <p>EDIT: Problem solved, but I guess I don't really understand why.</p> <p>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.</p> <p>So now my question is: .obj files need to be linked like libraries if they are not generated along with the executable?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload