some problems I'm getting...

Started by
5 comments, last by Kasooi 20 years, 8 months ago
I''m getting this: C:\WINDOWS\TEMP\ccmKE8fb.o: In function `DD_Init(int, int, int)'': //C/windows/desktop/source/game/Gpdumb1.cpp:689: undefined reference to `DirectDrawCreate@12'' I get that when I compile my game thing. I''m using dev C++ and I got libddraw.a linked and a file called gpdumb1.cpp linked which this code is in:
int DD_Init(int width, int height, int bpp)
{
// this function initializes directdraw
int index; // looping variable
// create object and test for error
if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK)
   return(0);

// set cooperation level to windowed mode normal
if (lpdd->SetCooperativeLevel(main_window_handle,
           DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | 
           DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK)
    return(0);

// set the display mode
if (lpdd->SetDisplayMode(width,height,bpp)!=DD_OK)
   return(0);

// set globals
screen_height = height;
screen_width = width;
screen_bpp = bpp;

// Create the primary surface
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

// we need to let dd know that we want a complex 
// flippable surface structure, set flags for that
ddsd.ddsCaps.dwCaps = 
  DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;

// set the backbuffer count to 1
ddsd.dwBackBufferCount = 1;

// create the primary surface
lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);

// query for the backbuffer i.e the secondary surface
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback);

// create and attach palette

// create palette data
// clear all entries defensive programming
memset(palette,0,256*sizeof(PALETTEENTRY));

// create a R,G,B,GR gradient palette
for (index=0; index < 256; index++)
    {
    // set each entry
    if (index < 64) 
        palette[index].peRed = index*4; 
    else           // shades of green
    if (index >= 64 && index < 128) 
        palette[index].peGreen = (index-64)*4;
    else           // shades of blue
    if (index >= 128 && index < 192) 
       palette[index].peBlue = (index-128)*4;
    else           // shades of grey
    if (index >= 192 && index < 256) 
        palette[index].peRed = palette[index].peGreen = 
        palette[index].peBlue = (index-192)*4;
    
    // set flags
    palette[index].peFlags = PC_NOCOLLAPSE;
    } // end for index

// now create the palette object
if (lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_INITIALIZE | DDPCAPS_ALLOW256,
                         palette,&lpddpal,NULL)!=DD_OK)
   return(0);

// attach the palette to the primary
if (lpddsprimary->SetPalette(lpddpal)!=DD_OK)
   return(0);

// clear out both primary and secondary surfaces
DD_Fill_Surface(lpddsprimary,0);
DD_Fill_Surface(lpddsback,0);

// return success
return(1);
} // end DD_Init 
The error is here: if (DirectDrawCreate(NULL,&lpdd,NULL)!=DD_OK) return(0); I don''t know whats wrong. It works with other things.
Advertisement
quote:undefined reference to `DirectDrawCreate@12'


That error is saying that its not finding a declaration for "DirectDrawCreate". Make sure you have ddraw.lib included in your project.

[edited by - Noods on August 13, 2003 12:20:34 AM]
quote:Original post by Noods
quote:undefined reference to `DirectDrawCreate@12''


That error is saying that its not finding a declaration for "DirectDrawCreate". Make sure you have ddraw.lib included in your project.

[edited by - Noods on August 13, 2003 12:20:34 AM]

To do that, would I use the #include <ddraw.lib> or would I use the linker. Because I used the linker one time and it came up as an illegal operation.

You can go like this:

#pragma comment(lib, "ddraw.lib")
You don''t include .lib files - you link to them.

You include header (.h and .hpp) files.

Try linking to ddraw.lib. Or whichever one comes with your project. And read the docs.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
quote:Original post by Kasooi
quote:Original post by Noods
quote:undefined reference to `DirectDrawCreate@12''


That error is saying that its not finding a declaration for "DirectDrawCreate". Make sure you have ddraw.lib included in your project.

[edited by - Noods on August 13, 2003 12:20:34 AM]

To do that, would I use the #include <ddraw.lib> or would I use the linker. Because I used the linker one time and it came up as an illegal operation.



No, no! Put it in your linker settings, or in the source file, thus:

#pragma comment(lib, "ddraw.lib")

There is no semi-colon at the end ''cause it''s a preprocessor statement.

Beginners and experts will find answers here.
that actually didn''t solve that problem. It solved another one though. But, I just moved that code block into the main file and it works perfectly fine.
Don''t really understand why it didn''t work in a seperate one...?

This topic is closed to new replies.

Advertisement