Compile errors in Dev-C++

Started by
7 comments, last by Thomas Jensen 18 years, 3 months ago
Hi everybody, this is my first post on gamedev.net. I've learned Cpp, did some windows programming, and then started learning game programming. I was using MS VC++ for a while, but it kept screwing up (often crashed while compiling) so I decided to try Dev-C++. When trying to compile the code written in VC++ in Dev-C++ problems ensues. When trying to compile my directX project I get this:

          main.cpp      In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
Line 112  main.cpp      [Warning] passing NULL used for non-pointer converting 1 of `HWND__* CreateWindowExA (line broken in two)
                        (DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'

                        [Linker error] undefined reference to `IID_IDirectDraw7'
                        [Linker error] undefined reference to `DirectDrawCreateEx@16'
Line 112  main.cpp      ld returned 1 exit status 
          Makefile.win  [Build Error]  [DXtest01.exe] Error 1
I understand the warning (I can see why sending a pointer to NULL is a bad idea), but I can't for the life of me figure out what is ment by ld returned 1 exit status? I should also mention that the the two directX linker errors goes away when removing the line DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL) I find those errors strange as I have included ddraw.h and set both the include and lib directories of directX under the compiler options. Here's the source of my project (don't worry, it's small):
#include <windows.h>

// The style of the main window, note the absence of WS_THICKFRAME and WS_MAXIMIZEBOX
#define MODDED_WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)

// DirectX includes ////////////////////////////////////////////////////////////
#include <ddraw.h>

// DirectX globals /////////////////////////////////////////////////////////////

LPDIRECTDRAW7 lpdd = NULL; // dd4 object

// Other globals ///////////////////////////////////////////////////////////////

HWND main_window_handle = NULL; // used to store the main window handle globally

// WindowProcedure /////////////////////////////////////////////////////////////

//  This function is called by the Windows function DispatchMessage()
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message) // handle the messages
    {
        case WM_CREATE:
            // do initialization stuff here
            break;
        case WM_DESTROY:
            PostQuitMessage(0); // send a WM_QUIT to the message queue
            break;
        default: // for messages that we don't deal with
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return(0);
}

// GameInitiate ////////////////////////////////////////////////////////////////

void Game_Init()
{
    // create IDirectDraw interface 7.0 object and test for error
    if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
        MessageBox(main_window_handle, "An error occurred while creating the DirectDraw7 interface.", "An error occurred", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
}

// GameMain ////////////////////////////////////////////////////////////////////

void Game_Main()
{

}

// GameShutdown ////////////////////////////////////////////////////////////////

void Game_Shutdown()
{

}

// WinMain /////////////////////////////////////////////////////////////////////

int WINAPI WinMain( HINSTANCE hThisInstance,    // Handle of the application
                    HINSTANCE hPrevInstance,    // Obsolete, once used to hold the handle of the app that launched this app
                    LPSTR lpszArgument,         // The command line + parameters used to run the app
                    int nFunsterStil)           // Used with ShowWindow()
{
    HWND hwnd;       // This is the handle for our main window
    MSG messages;    // Here messages to the application are saved


    // Data structure for the window class
    WNDCLASSEX winclass = {                  // ---Variable names------Descriptions------
    sizeof(WNDCLASSEX),                     // cbSize              The size of the winclass, just use: sizeof(WNDCLASSEX)
    CS_CLASSDC | CS_HREDRAW | CS_VREDRAW,    // style               CS_CLASSDC is required when using gdi
    WindowProcedure,                         // lpfnWndProc         This is the function that handels windows messages (does WM_CREATE, WM_DESTROY and WM_PAINT ring a bell?)
    0,                                       // cbClsExtra          Extra class memory, nobody will ever use this
    0,                                       // cbWndExtra          Extra window memory, this is just as useless
    hThisInstance,                           // hInstance           The instance of the application, recived as a parameter to WinMain, it's used everywhere so hold on to it
    LoadIcon(NULL, IDI_APPLICATION),         // hIcon               (NULL, IDI_APPLICATION), (hThisInstance, "Xicon")
    LoadCursor(NULL, IDC_ARROW),             // hCursor             The curser show when hovering the window, for the default use: LoadCursor(NULL, IDC_ARROW), or maybe LoadCursor(hThisInstance, "CustomCuserName") if you have made your own
    GetSysColorBrush(COLOR_MENU),            // hbrBackground       The window background color, use this: GetSysColorBrush(COLOR_MENU)
    NULL,                                    // lpszMenuName        The default menu of the windows created using this window class, menus are defined in the resource file
    "WINCLASS1",                            // lpszClassName       Identifies the class, used when creating windows, has to be unique
    LoadIcon(NULL, IDI_APPLICATION)};        // hIconSm             Small icon, use: LoadIcon(NULL, IDI_APPLICATION) for default LoadIcon(hThisInstance, or "CustomIconName") if you have made your own


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

    // create the main window, bail if problem
    if (!(hwnd = CreateWindowEx(                  // ---Variable names------Descriptions------
            NULL,                                 // dwExStyle           Extended style, use: WS_EX_TOPMOST to set the window always on top, this can also be changed run-time with the SetWindowPos function
            "WINCLASS1",                        // lpClassName         The name of the window class used to create the window, defined in the lpszClassName variable of the window class
            "Template window",                 // lpWindowName        The title appearing in the title bar of the window, or the text appearing on buttons and the like
            MODDED_WS_OVERLAPPEDWINDOW,           // dwStyle             General style, for resizable window, use: WS_OVERLAPPEDWINDOW, and for a none-resizable use: MODDED_WS_OVERLAPPEDWINDOW. For starting with the window shown use: WS_VISIBLE
            CW_USEDEFAULT,CW_USEDEFAULT,          // x, y                Initial x,y coordinats, use: CW_USEDEFAULT for each of them for default position
            375, 544,                            // nWidth, nHeight     Initial width and height of the window
            NULL,                                 // hWndParent          Handle to parent window, (in most cases probaly the main window handle, hwnd)
            NULL,                                 // hMenu               Handle to menu, menus are defined in the resource file, for no menu (or default menu set by the window class) use: NULL
            hThisInstance,                        // hInstance           Instance of the application, recieved as a parameter to WinMain
            NULL)))                               // lpParam             Extra creation parameters, it has something to do with the WM_CREATE message, not vital (don't know, don't care)
    return(0);

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

    // store the main window handle globally
    main_window_handle = hwnd;

    // initialize game here
    Game_Init();

    // enter main event loop
    while(TRUE)
    {
        // test if there is a message in queue, if so get it
        if (PeekMessage(&messages,NULL,0,0,PM_REMOVE))
        {
            // test if this is a quit
            if (messages.message == WM_QUIT)
                break;

            // translate any accelerator keys
            TranslateMessage(&messages);

            // send the message to the window proc
            DispatchMessage(&messages);
        } // end if

        // main game processing goes here
        Game_Main();

    } // end while

    // closedown game here
    Game_Shutdown();

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



I have been stuck with this for quite some time and figured that some of you gurus would be able to help me. Any help, any comments, will be highly appreciated. Thank you.
Advertisement
Are you linking properly? Under project options (forgot which menu :)) there should be a 'linker' space. Under that write -lLIBRARYNAME, when 'LIBRARYNAME' is just the name (no extension) of the libLIBRARYNAME.a file. Note dev-cpp uses libWHATEVERNAME.a files, not WHATEVERNAME.lib files.

Welcome, and I also suggest you try code::blocks studio from codeblocks.org. The syntax highlighting is better and the package is much smaller and cleaner, and the linking is made very easy.

C++
Oh, and uhh, return status 1 means there was an error in GCC, which is the compiler dev-cpp uses.

C++
Sorry, edited this post, it didn't make sense. I'm new to this stuff...
Quote:Original post by Anonymous Poster
Are you linking properly? Under project options (forgot which menu :)) there should be a 'linker' space. Under that write -lLIBRARYNAME, when 'LIBRARYNAME' is just the name (no extension) of the libLIBRARYNAME.a file. Note dev-cpp uses libWHATEVERNAME.a files, not WHATEVERNAME.lib files.


I just searched the directX SDK, and there is no files with *.a extentions. Maybe I'm being a bit slow, but I don't understand your explanation (english is not my native language either). Please try to help me, I really want this to work... :(

Did you mean something like this?:

Screenshot from Dev-C++

[Edited by - Thomas Jensen on January 1, 2006 3:57:46 PM]
That should work. I have .lib files linked and they work fine.
Also, make sure that your directories are set correctly.
If it can be seen in the world, it can be built in 3D
Quote:Original post by MikeRow
That should work. I have .lib files linked and they work fine.
Also, make sure that your directories are set correctly.

Thanks for the reply. I still get the same error messages though. Here's how I have set my directories:

Screenshot from Dev-C++ Screenshot from Dev-C++

I really doesn't understand why it doesn't work...

[Edited by - Thomas Jensen on January 2, 2006 8:59:00 PM]
its because dev-c++ uses a diferent library format tham MSVC++ they use .a formats not .lib formats and yuo cant just rename them you have to reformat it if you look close anough on the internet you should fined a format converter.
GOOD LUCK.
Quote:Original post by Anonymous Poster
its because dev-c++ uses a diferent library format tham MSVC++ they use .a formats not .lib formats and yuo cant just rename them you have to reformat it if you look close anough on the internet you should fined a format converter.
GOOD LUCK.


Thanks for your help, though I have already moved on to trying Microsoft Visual C++ 2005. It seems that Microsoft really made an effort to make everything very difficult this time, so I just might give up and go back to Dev-C++.

Thank you

This topic is closed to new replies.

Advertisement