Question About Linker Errors In Dev-C++

This is a discussion on Question About Linker Errors In Dev-C++ within the C++ Programming forums, part of the General Programming Boards category; I continually get errors such as "[Linker error] undefined reference to `GetStockObject@4'". What does it all mean? What does it ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    40

    Question About Linker Errors In Dev-C++

    I continually get errors such as "[Linker error] undefined reference to `GetStockObject@4'". What does it all mean? What does it mean when it says that and what can I do to take care of it?
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    @ ShadowMetis :

    Please give some prog code, let's find out error?

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    40
    It's pretty much directly from the book. That's why I'm scratch'n my head over it.


    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY WinMain(HINSTANCE hInstance, 
                         HINSTANCE hPrevInstance, 
                         LPSTR     lpCmdLine, 
                         int       nCmdShow)
    {
        WNDCLASS WndClass;
        WndClass.style = 0;
        WndClass.cbClsExtra = 0;
        WndClass.cbWndExtra = 0;
        WndClass.lpfnWndProc = WndProc;
        WndClass.hInstance = hInstance;
        WndClass.hbrBackground = (HBRUSH) (COLOR_MENU+1);
        WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
        WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        WndClass.lpszMenuName = 0;
        WndClass.lpszClassName = "WinProg";
        
        RegisterClass(&WndClass);
        
        HWND hWindow;
        hWindow = CreateWindow("WinProg","WinSock Trial",
                               WS_OVERLAPPEDWINDOW,
                               0,0,600,500,NULL,NULL,
                               hInstance, NULL);
        ShowWindow (hWindow, nCmdShow);
        
        UpdateWindow (hWindow);
        MSG Message;
        while (GetMessage(&Message, NULL, 0, 0));
        {
            DispatchMessage(&Message);
        }
        
        return (Message.wParam);
    }
    
    LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
                              WPARAM wParam, LPARAM lParam)
    {
        switch(uiMessage)
        {
            case WM_PAINT:
                HDC hdc;
                PAINTSTRUCT ps;
                hdc = BeginPaint (hWnd, &ps);
                HFONT hFont;
                
                hFont = (HFONT) GetStockObject (ANSI_FIXED_FONT);
                SelectObject(hdc, hFont);
                SetTextColor (hdc, RGB(0,0,180));
                SetBkColor (hdc, RGB(190,180,200));
                SetTextAlign (hdc, TA_LEFT);
                char *string1;
                string1 = new char[99];
                lstrcpy (string1,"test test test test test test test test test test test test test test test test test test test test");
                TextOut (hdc, 10, 40, string1, lstrlen(string1));
                        
                EndPaint (hWnd, &ps);    
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
            default:
                return DefWindowProc (hWnd, uiMessage,
                                      wParam, lParam);
                
        }
    }


    [Linker error] undefined reference to `GetStockObject@4' [Linker error] undefined reference to `SelectObject@8'
    [Linker error] undefined reference to `SetTextColor@8'
    [Linker error] undefined reference to `SetBkColor@8'
    [Linker error] undefined reference to `SetTextAlign@8'
    [Linker error] undefined reference to `TextOutA@20'


    It seems like it's only the GDI functions
    Last edited by ShadowMetis; 08-18-2004 at 12:48 AM.
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    40
    I'd still like to have my question answered...
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Which compiler are you using?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    40
    It says right in the title that it's Dev-C++.........
    Code:
    #include <iostream.h>
    int var;
    int test();
    int main() { 
     cout << "Please input your language:\n 1. C (C,C++,C#)\n 2. VB\n 3. Other\n";
     cin >> var;
     return test(); }
    int test() {  
     if(var == 1) {
      cout << "Y0u 4r3 t3h 1337\n";
      system("PAUSE");
      return main(); }
     else if(var == 2) {
      cout << "N00B3R!\n";
      system("PAUSE");
      return main(); }
     else if(var == 3) {
      cout << "You were not thought of.\n";
      system("PAUSE");
      return main(); }
     else {      
      return 0; }}

  7. #7
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I assume you created a project.

    Go to project options
    Make sure under type it is Win32 GUI
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  8. #8
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by JaWiB
    I assume you created a project.

    Go to project options
    Make sure under type it is Win32 GUI

    its not mandatory to go to project options. just go to file
    new project
    windows application

    and you should be set. For additonal functionality and options you can then go to project options. for example if you want to add an icon, provide additonal parameters etc.

  9. #9
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I was assuming he already made the project and just needed to change the settings...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Quote Originally Posted by ShadowMetis
    It says right in the title that it's Dev-C++.........
    I meant the compiler, not the GUI. I know of some people who use MSVC's compiler, and some who use the default MinGW32.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev C++ question
    By TCB in forum C Programming
    Replies: 11
    Last Post: 04-09-2006, 12:15 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Linker Errors...
    By manudathg in forum C Programming
    Replies: 4
    Last Post: 10-04-2005, 06:50 PM
  4. Linker Errors in OpenGL
    By Sentral in forum Game Programming
    Replies: 2
    Last Post: 07-19-2005, 05:29 PM
  5. Dev C++/mySQL linker errors
    By WDT in forum C Programming
    Replies: 2
    Last Post: 03-30-2004, 03:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21