Linker Error

paddymann

Mitglied
Tach!

Ich bekomme sehr oft die gleichen Linker Error, wenn ich nen Quellcode compilieren will. Und zwar sagt der Compiler: [Linker Error] undefined reference to 'MoveToEx@16'
[Linker Error] undefined reference to 'LineTo@12'
Id returned 1 exit status

Ich benutze den Dev-C++ Compiler. Was hat es mit den Fehlern auf sich wenn ich die bei unterschiedlichen Projekten bekomme
Danke!
 
moin


Das heisst das du versuchst eine der beiden Funktionen zu benutzen, jedoch findet er sie nicht.
Wahrscheinlich ist eine benötigte Libary nciht eingebunden.

Poste mal nen Quellcode bei dem der Fehler erscheint.


mfg
umbrasaxum
 
Code:
#include <windows.h>
#include <string.h>

const char *CLASSNAME = "Tutorial", *WINNAME = "Tutorial 3 - The Graphics";

HDC hdc = NULL;

LRESULT CALLBACK WndProc(HWND hWnd, unsigned int iMessage, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
	HWND hWnd;
	MSG Message;
	WNDCLASS WndClass;
	memset(&WndClass, 0, sizeof(WndClass));
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
	WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon(hInstance, NULL);
	WndClass.hInstance = hInstance;
	WndClass.lpfnWndProc = WndProc;
	WndClass.lpszClassName = CLASSNAME;
	WndClass.style = CS_HREDRAW | CS_VREDRAW;
	if(!RegisterClass(&WndClass))
		return 0;
        
	hWnd = CreateWindow(CLASSNAME, WINNAME, WS_OVERLAPPEDWINDOW,
											CW_USEDEFAULT, CW_USEDEFAULT, 300, 100,
											NULL, NULL, hInstance, NULL);

	ShowWindow(hWnd, nCmdShow);
    
	while(GetMessage(&Message, hWnd, 0, 0))
	{
		TranslateMessage(&Message);
		DispatchMessage(&Message);
	}
	return Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	switch(iMessage)
	{
	case WM_LBUTTONDOWN:
		hdc = GetDC(hWnd);
		if(hdc)
		{
			short xp = LOWORD(lParam);
			short yp = HIWORD(lParam);			
			MoveToEx(hdc, xp, yp, NULL);
		}
		break;
	case WM_LBUTTONUP:
		if(hdc)
			ReleaseDC(hWnd, hdc);
		hdc = NULL;
		break;
	case WM_MOUSEMOVE:
		if(hdc)
		{
			short xp = LOWORD(lParam);
			short yp = HIWORD(lParam);
			LineTo(hdc, xp, yp);
		}
		break;
	case WM_CLOSE:
		if(MessageBox(hWnd, "Do you really want to quit?", "Message", MB_YESNO) == IDYES)
		{
			if(hdc)
				ReleaseDC(hWnd, hdc);
			PostQuitMessage(0);
		}
		break;
	default:
		return DefWindowProc(hWnd, iMessage, wParam, lParam);
	}
	return 0;
}
 
moin


Hab bei deinem Code mal die Code-Tags eingefügt.

Guckmal nach ob die Gdi32.lib eingebunden wird.


mfg
umbrasaxum
 
moin


Irgendwo in den Compiler oder Linker einstellungen muss stehen welche Bibliotheken includiert werden.


mfg
umbrasaxum
 
Ich hab jetzt den GUI32 Typ noch eingefügt(den hab ich in der Bibliothek so gefunden). Jetzt funktioniert das ganze. Besten Dank!
 
Ich hab hier schon wieder nen Linker Error den ich nicht weg kriege.
"undefined reference to 'Z15WindowProcedureP6HWnd__jjl@16".
Was ist da wieder faul? Ich benutze überigens den Dev C++ Compiler.
Danke
 
OK. Hier mal mein Code:

Code:
#include <windows.h>
#include <stdio.h>
/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

static HMENU hMenu;
POINT  point;
int    iAuswahl;
char   szText[64];

switch (message)
{
   case WM_CREATE:
      hMenu = CreatePopupMenu (); // Menu anlegen 
// und rein mit den Einträgen.. Der 2te Parameter ist die ID des jew. Eintrages 
      InsertMenu (hMenu, 0, MF_BYPOSITION, 0, "Menueintrag");
      InsertMenu (hMenu, 1, MF_BYPOSITION, 1, "Menueintrag");
      InsertMenu (hMenu, 2, MF_SEPARATOR, 0, NULL); // Separator 
      InsertMenu (hMenu, 3, MF_BYPOSITION, 3, "Menueintrag");
      return 0 ;

   case WM_CONTEXTMENU: // jetzt könnte ein Contextmenu angezeigt werden sollen 
// Koordinaten des Mauszeigers ermitteln 
      POINTSTOPOINT (point, lParam);
// Sind point.x und point.y == -1, so wurde die Nachricht 
// als Ergebnis auf ein Tastatur-Ereignis gesendet. 
      if ((point.x == -1) && (point.y == -1))
      {
         point.x = point.y = GetSystemMetrics (SM_CXEDGE);
         ClientToScreen (hwnd, &point); // Die Koordinaten auf unser Fenster legen 
      }
// WM_CONTEXTMENU nicht verarbeiten, wenn ein Rechtsklick 
// in die Titelleiste vorliegt. Hier soll schließlich das 
// Systemmenu angezeigt werden 
      else if (HTCLIENT != SendMessage (hwnd, WM_NCHITTEST, 0, lParam))
      {
         break;
      }

// Das Menu an der Position des Mauszeigers anzeigen 
      iAuswahl = (int) TrackPopupMenu (hMenu, TPM_CENTERALIGN | TPM_LEFTBUTTON |
                                       TPM_RETURNCMD, point.x, point.y, 0, hwnd, 0);

// Ausgabe welches Item gewählt wurde 
      sprintf (szText, "Itemnummer %d wurde ausgewählt", iAuswahl);
      MessageBox (NULL, szText, "Nachricht", MB_OK);
      return 0;

   case WM_DESTROY:
      DestroyMenu (hMenu); // Aufräumen 
      PostQuitMessage (0);
      return 0;
   }

  return DefWindowProc (hwnd, message, wParam, lParam);
}
Wenn du mir den Fehler sagen köntest wer das echt gut :)
 
Zurück