Solved "Undefined reference to" issues
-
Hi,
I am in charge of fixing bugs and improving a C++ program that was written in Qt back in 2008.
After fixing some errors, I get a list of more 500 errors that starts with "undefined reference to ..."
An example is:/* MODULE: CALCWND.CPP VERSION: 2.2 */ #include <QPainter> #include <QPaintEvent> #include <QPaintEngine> #include <QScrollbar> #include <QTime> #include <windows.h> #include <cmath> #include <QtDebug> #include "calcwnd.h" #include "xrda_def.h" #include "xrdawnd.h" #include "xrdproject.h" bool SortByE = true; extern XrdaWnd *Wnd; extern XRDProject *Proj; Calc::Calc(int th, int tk, int tl) // initialization of Calc class object { h = th; k = tk; l = tl; Ecalc = 0.; Icalc = 0.; Eobs = 0; Iobs = 0; } void Calc::EnterE(float E) { Ecalc = E; } void Calc::EnterI(float I) { Icalc = I; } void Calc::CheckObserved() { Peak *P; if (h != 0 || k != 0 || l != 0) for (PEAKS::const_iterator iter = Proj->Phases[Proj->SelPhaseNo]->Peaks.begin(); iter != Proj->Phases[Proj->SelPhaseNo]->Peaks.end(); iter++) { P = (*iter).get(); if ((P->h == h) && (P->k == k) && (P->l == l)) { Eobs = P->Eobs; Iobs = P->Iobs; } } } // sort by increasing energy but dec. intensities bool calc_compare(const std::shared_ptr<Calc> &a, const std::shared_ptr<Calc> &b) { if (SortByE && a->Ecalc < b->Ecalc) { return true; } else if (!SortByE && a->Icalc > b->Icalc) { return true; } return false; } /* TCalcWnd::TCalcWnd(PTWindowsObject AParent, LPSTR ATitle): TWindow(AParent, ATitle) { Attr.Style |= WS_VSCROLL | WS_HSCROLL; Scroller = new TScroller(this, 8, 15, 100, 100); Scroller->AutoMode = TRUE; CalcData = new TEIColl(50, 10); } TCalcWnd::~TCalcWnd() { delete CalcData; delete Scroller; } void TCalcWnd::SetupWindow() { TWindow::SetupWindow(); switch (phaseno) { case 1: SetCaption("Phase I - Calculated Energies and Intensities"); break; case 2: SetCaption("Phase II - Calculated Energies and Intensities"); break; case 3: SetCaption("Phase III - Calculated Energies and Intensities"); break; case 4: SetCaption("Phase IV - Calculated Energies and Intensities"); break; case 5: SetCaption("Phase V - Calculated Energies and Intensities"); break; default: SetCaption("Calculated Energies and Intensities"); break; } } void TCalcWnd::KeyInput(RTMessage Msg) { int ScanCode = MapVirtualKey(Msg.WParam, 0); DefWndProc(Msg); switch(ScanCode) { case 0x50: Scroller->ScrollBy(0, 1); break; case 0x48: Scroller->ScrollBy(0, -1); break; case 0x47: Scroller->ScrollTo(0, 0); break; case 0x51: Scroller->ScrollBy(0, 20); break; case 0x49: Scroller->ScrollBy(0, -20); break; default: SendMessage(Parent->HWindow, WM_KEYDOWN, Msg.WParam, Msg.LParam); } }*/ CalcWnd::CalcWnd(QWidget *parent) : QWidget(parent), CalcData(calc_compare) { setPalette(QPalette(QColor(255, 255, 255))); setAutoFillBackground(true); setAttribute(Qt::WA_NativeWindow); phaseno = 0; pix = 0; redrawPixmap = true; } QSize CalcWnd::sizeHint() const { return QSize(700, 500); } void CalcWnd::Reinitialize() { NewPhase(1); } void CalcWnd::SortByEnergy(bool yesno) { CALC TempSort(calc_compare); Calc *C1, *C2; if (SortByE != yesno) { SortByE = yesno; for (CALC::iterator iter = CalcData.begin(); iter != CalcData.end(); iter++) { C1 = (*iter).get(); C2 = new Calc(C1->h, C1->k, C1->l); C2->Eobs = C1->Eobs; C2->Iobs = C2->Iobs; C2->Ecalc = C1->Ecalc; C2->Icalc = C1->Icalc; std::shared_ptr<Calc> ptr(C2); TempSort.insert(ptr); } CalcData.clear(); for (CALC::iterator iter = TempSort.begin(); iter != TempSort.end(); iter++) { C1 = (*iter).get(); C2 = new Calc(C1->h, C1->k, C1->l); C2->Eobs = C1->Eobs; C2->Iobs = C2->Iobs; C2->Ecalc = C1->Ecalc; C2->Icalc = C1->Icalc; std::shared_ptr<Calc> ptr(C2); CalcData.insert(ptr); } this->RedrawPixmap(); } } void CalcWnd::NewPhase(int PhaseNo) { phaseno = PhaseNo; CalcData.clear(); switch (phaseno) { case 1: emit windowTitleChanged("Phase I - Calculated Energies and Intensities"); break; case 2: emit windowTitleChanged("Phase II - Calculated Energies and Intensities"); break; case 3: emit windowTitleChanged("Phase III - Calculated Energies and Intensities"); break; case 4: emit windowTitleChanged("Phase IV - Calculated Energies and Intensities"); break; case 5: emit windowTitleChanged("Phase V - Calculated Energies and Intensities"); break; case 6: emit windowTitleChanged("Phase VI - Calculated Energies and Intensities"); break; default: emit windowTitleChanged("Calculated Energies and Intensities"); break; } this->RedrawPixmap(); } void CalcWnd::RedrawPixmap() { this->update(); redrawPixmap = true; } void CalcWnd::RedrawPixmap(const QRect &rect) { this->update(rect); redrawPixmap = true; } void CalcWnd::paintEvent(QPaintEvent *e) { /*if (redrawPixmap) { DoRedrawPixmap(e->rect()); redrawPixmap = false; } QPainter p(this); p.drawPixmap(e->rect(), *pix, e->rect());*/ DoRedrawPixmap(e->rect()); } void CalcWnd::DoRedrawPixmap(const QRect &rect) { /*char buf[256]; int XI = 40, YI = 58; PAINTSTRUCT ps; ps.rcPaint.left = rect.left(); ps.rcPaint.top = rect.top(); ps.rcPaint.right = rect.right(); ps.rcPaint.bottom = rect.bottom(); // Create new pixmap (Note : each item is 17 pixels in height) delete pix; int WndY = 51+(int)ceil(CalcData.size()*17.0/2.0); if (WndY < Wnd->scrollCalc->size().height()) { WndY = Wnd->scrollCalc->size().height(); } pix = new QPixmap(800, WndY); this->resize(pix->size()); QPainter p(pix); p.fillRect(pix->rect(), QBrush(QColor(255,255,255))); p.setPen(QPen(QBrush(QColor(0, 0, 0)), 3)); p.drawLine(2, 35, 1000, 35); p.drawLine(325, 25, 325, 1500); p.setFont(QFont("Arial", 9, QFont::Bold)); p.drawText(40, 26, "hkl"); p.drawText(90, 26, "E calc"); p.drawText(140, 26, "E obs"); p.drawText(190, 26, "I calc"); p.drawText(240, 26, "I obs"); p.drawText(350, 26, "hkl"); p.drawText(400, 26, "E calc"); p.drawText(450, 26, "E obs"); p.drawText(500, 26, "I calc"); p.drawText(550, 26, "I obs"); p.setFont(QFont("Arial", 9, QFont::Normal)); int calcSize = CalcData.size(); CALC::const_iterator iter = CalcData.begin(); for (int i = 0; iter != CalcData.end() && i < 0.5*calcSize; iter++, i++) { Calc *C = (*iter).get(); sprintf(buf, "%d%d%d", C->h, C->k, C->l); p.drawText(XI, YI, buf); sprintf(buf, "%6.3f", C->Ecalc); p.drawText(XI+50, YI, buf); if (C->Eobs != 0) { sprintf(buf, "%6.3f", C->Eobs); } else { strcpy(buf, " -"); } p.drawText(XI+100, YI, buf); sprintf(buf, "%6.3f", C->Icalc); p.drawText(XI+150, YI, buf); if (C->Iobs != 0) { sprintf(buf, "%6.3f", C->Iobs); } else { strcpy(buf, " -"); } p.drawText(XI+200, YI, buf); YI += 17; } XI = 350; YI = 58; for (; iter != CalcData.end(); iter++) { Calc *C = (*iter).get(); sprintf(buf, "%d%d%d", C->h, C->k, C->l); p.drawText(XI, YI, buf); sprintf(buf, "%6.3f", C->Ecalc); p.drawText(XI+50, YI, buf); if (C->Eobs != 0) { sprintf(buf, "%6.3f", C->Eobs); } else { strcpy(buf, " -"); } p.drawText(XI+100, YI, buf); sprintf(buf, "%6.3f", C->Icalc); p.drawText(XI+150, YI, buf); if (C->Iobs != 0) { sprintf(buf, "%6.3f", C->Iobs); } else { strcpy(buf, " -"); } p.drawText(XI+200, YI, buf); YI += 17; }*/ int i; LOGFONT LogFont; HFONT Font, OldFont; HPEN Pen, OldPen; char buf[100]; int XI = 50, YI = 50; Calc *C; // Calculate the size of the widget for holding all items // Each item is 17 pixel long int ContentY = 51+CalcData.size()*17; int WndY = Wnd->calcWnd->size().height()-48; this->resize(800, max(ContentY, WndY)); // Prepare the backbuffer for drawing QPainter p(this); HWND hwnd = (HWND)p.paintEngine(); HDC PaintDC = GetDC(hwnd); //HDC PaintDC = p.paintEngine()->getDC(); QPoint wnd = mapTo(window(), QPoint(0,0)); POINT org; GetDCOrgEx(PaintDC, &org); SetViewportOrgEx(PaintDC, wnd.x(), wnd.y(), &org); qDebug() << "Time: " << QTime::currentTime(); qDebug() << "wnd: " << wnd; qDebug() << "size(): " << size(); // Set the clipping region HRGN hrgn = CreateRectRgn(rect.left()+wnd.x(), rect.top()+wnd.y(), rect.right()+wnd.x()+1, rect.bottom()+wnd.y()+1); SelectClipRgn(PaintDC, hrgn); LogFont.lfHeight = 15; LogFont.lfWidth = 0; LogFont.lfEscapement = 0; LogFont.lfOrientation = 0; LogFont.lfWeight = FW_NORMAL; LogFont.lfItalic = 0; LogFont.lfUnderline = 0; LogFont.lfStrikeOut = 0; LogFont.lfCharSet = ANSI_CHARSET; LogFont.lfOutPrecision = OUT_DEFAULT_PRECIS; LogFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; LogFont.lfQuality = DEFAULT_QUALITY; LogFont.lfPitchAndFamily = VARIABLE_PITCH | FF_DONTCARE; strcpy(LogFont.lfFaceName, "TIMES"); Font = CreateFontIndirect(&LogFont); // create font Pen = CreatePen(PS_SOLID, 3, 0x00000000); // create pen OldPen = (HPEN) SelectObject(PaintDC, Pen); MoveToEx(PaintDC, 2, 35, 0); LineTo(PaintDC, 1000, 35); MoveToEx(PaintDC, 325, 25, 0); LineTo(PaintDC, 325, max(ContentY, WndY)); SelectObject(PaintDC, OldPen); DeleteObject(Pen); // delete pen OldFont = (HFONT) SelectObject(PaintDC, Font); strcpy(buf, "hkl"); TextOut(PaintDC, 50, 15, buf, strlen(buf)); strcpy(buf, "E calc"); TextOut(PaintDC, 100, 15, buf, strlen(buf)); strcpy(buf, "E obs"); TextOut(PaintDC, 150, 15, buf, strlen(buf)); strcpy(buf, "I calc"); TextOut(PaintDC, 200, 15, buf, strlen(buf)); strcpy(buf, "I obs"); TextOut(PaintDC, 250, 15, buf, strlen(buf)); strcpy(buf, "hkl"); TextOut(PaintDC, 350, 15, buf, strlen(buf)); strcpy(buf, "E calc"); TextOut(PaintDC, 400, 15, buf, strlen(buf)); strcpy(buf, "E obs"); TextOut(PaintDC, 450, 15, buf, strlen(buf)); strcpy(buf, "I calc"); TextOut(PaintDC, 500, 15, buf, strlen(buf)); strcpy(buf, "I obs"); TextOut(PaintDC, 550, 15, buf, strlen(buf)); int calcSize; CALC::const_iterator iter; for (i = 0, iter = CalcData.begin(), calcSize = CalcData.size(); iter != CalcData.end() && i < 0.5*calcSize; iter++, calcSize++) { C = (*iter).get(); sprintf(buf, "%d%d%d", C->h, C->k, C->l); TextOut(PaintDC, XI, YI, buf, strlen(buf)); sprintf(buf, "%6.3f", C->Ecalc); TextOut(PaintDC, XI+50, YI, buf, strlen(buf)); if (C->Eobs != 0) sprintf(buf, "%6.3f", C->Eobs); else strcpy(buf, " -"); TextOut(PaintDC, XI+100, YI, buf, strlen(buf)); sprintf(buf, "%6.3f", C->Icalc); TextOut(PaintDC, XI+150, YI, buf, strlen(buf)); if (C->Iobs != 0) sprintf(buf, "%6.3f", C->Iobs); else strcpy(buf, " -"); TextOut(PaintDC, XI+200, YI, buf, strlen(buf)); YI += 17; } XI = 350; YI = 50; for (; iter != CalcData.end(); iter++) { C = (*iter).get(); sprintf(buf, "%d%d%d", C->h, C->k, C->l); TextOut(PaintDC, XI, YI, buf, strlen(buf)); sprintf(buf, "%6.3f", C->Ecalc); TextOut(PaintDC, XI+50, YI, buf, strlen(buf)); if (C->Eobs != 0) sprintf(buf, "%6.3f", C->Eobs); else strcpy(buf, " -"); TextOut(PaintDC, XI+100, YI, buf, strlen(buf)); sprintf(buf, "%6.3f", C->Icalc); TextOut(PaintDC, XI+150, YI, buf, strlen(buf)); if (C->Iobs != 0) sprintf(buf, "%6.3f", C->Iobs); else strcpy(buf, " -"); TextOut(PaintDC, XI+200, YI, buf, strlen(buf)); YI += 17; } SelectObject(PaintDC, OldFont); DeleteObject(Font); // delete font // Restore viewport state SetViewportOrgEx(PaintDC, org.x, org.y, 0); // Release backbuffer handle //p.paintEngine()->releaseDC(PaintDC); ReleaseDC(hwnd, PaintDC); }
returns the issues:
undefined reference to '__imp_GetDCOrgEx' line 333 undefined reference to '__imp_SetViewportOrgEx' line 334 and 438 undefined reference to '__imp_CreateRectRgn' line 342 undefined reference to '__imp_SelectClipRgn' line 343 undefined reference to '__imp_CreateFontIndirectA' line 359 undefined reference to '__imp_CreatePen' line 360 undefined reference to '__imp_SelectObject' line 361, 366, 368 and 434 undefined reference to '__imp_MoveToEx' line 362 and 364 undefined reference to '__imp_LineTo' line 363 and 365 undefined reference to '__imp_DeleteObject' line 367 and 435 undefined reference to '__imp_TextOutA' all calls from line 370 to 431
Note: This is the code of an unfinished version because the final version was lost.
I have no idea what to fix these issues.
I'm new to Qt and relatively new to C++.
Thanks in advance. -
Those are all Windows GDI APIs.
It seems that you haven't linked Gdi32.lib to your project. -
Those are all Windows GDI APIs.
It seems that you haven't linked Gdi32.lib to your project. -
It works.
Thank you so much.