Forum: PC-Programmierung Probleme mit SDL


von Programmierer (Gast)


Lesenswert?

Ich folgendes Problem mit der Benutzung der SDL Bibliothek.
Wenn ich diesen Code übersetzte, erhalte ich von Microsoft Visul Studio 
C++ 2008 folgende Meldungen:

Warnung  1  warning C4700: Die nicht initialisierte lokale Variable 
"mColor" wurde verwendet. 
d:\sdl_tetris\sdl_tetris\sdl_tetris\sdl_tetris.cpp  101  SDL_Tetris

Fehler  2  error LNK2019: Verweis auf nicht aufgelöstes externes
Symbol "__imp__boxColor" in Funktion ""void __cdecl 
DrawRectangle(int,int,int,int,enum color)" 
(?DrawRectangle@@YAXHHHHW4color@@@Z)".  SDL_Tetris.obj  SDL_Tetris

Fehler  3  fatal error LNK1120: 1 nicht aufgelöste externe Verweise. 
D:\SDL\SDL_Tetris\SDL_Tetris\Debug\SDL_Tetris.exe  1  SDL_Tetris


Programmcode:
1
#include "stdafx.h"
2
#include <string.h>
3
4
/* -- Include the precompiled libraries -- */
5
#ifdef WIN32
6
#pragma comment(lib, "SDL.lib")
7
#pragma comment(lib, "SDLmain.lib")
8
#pragma comment(lib, "SDL_image.lib")
9
#endif
10
11
#include "SDL.h"
12
#include "SDL_image.h"
13
#include <SDL_gfxPrimitives.h>
14
15
16
#include "bodies.h"
17
18
SDL_Surface *screen, *image[6];
19
SDL_Event e;
20
SDL_Rect rect,background;
21
22
unsigned char *bKey;
23
int quit = 0;
24
unsigned int i=0;
25
26
#define BOARD_LINE_WIDTH 6      // Width of each of the two lines that delimit the board
27
#define BLOCK_SIZE 16        // Width and Height of each block of a piece
28
#define BOARD_POSITION 320      // Center position of the board from the left of the screen
29
#define BOARD_WIDTH 10        // Board width in blocks 
30
#define BOARD_HEIGHT 20        // Board height in blocks
31
#define MIN_VERTICAL_MARGIN 20    // Minimum vertical margin for the board limit     
32
#define MIN_HORIZONTAL_MARGIN 20  // Minimum horizontal margin for the board limit
33
#define PIECE_BLOCKS 5  
34
35
int mBoard [BOARD_WIDTH][BOARD_HEIGHT];
36
enum { POS_FREE, POS_FILLED };
37
enum color {BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE, COLOR_MAX};
38
static Uint32 mColors [COLOR_MAX] = {0x000000ff,0xff0000ff, 0x00ff00ff, 0x0000ffff,
39
                               0x00ffffff, 0xff00ffff, 0xffff00ff,0xffffffff};
40
41
void InitBoard(void);
42
void StorePiece (int pX, int pY, int pPiece, int pRotation);
43
void DrawPiece (int pX, int pY, int pPiece, int pRotation);
44
45
void InitBoard(void)
46
{
47
  for (int i = 0; i < BOARD_WIDTH; i++)
48
    for (int j = 0; j < BOARD_HEIGHT; j++)
49
      mBoard[i][j] = POS_FREE;
50
}
51
52
void StorePiece (int pX, int pY, int pPiece, int pRotation)
53
{
54
  // Store each block of the piece into the board
55
  for (int i1 = pX, i2 = 0; i1 < pX + PIECE_BLOCKS; i1++, i2++)
56
  {
57
    for (int j1 = pY, j2 = 0; j1 < pY + PIECE_BLOCKS; j1++, j2++)
58
    {  
59
      // Store only the blocks of the piece that are not holes
60
      if (GetBlockType (pPiece, pRotation, j2, i2) != 0)    
61
        mBoard[i1][j1] = POS_FILLED;  
62
    }
63
  }
64
}
65
66
void DrawRectangle (int pX1, int pY1, int pX2, int pY2, enum color pC)
67
{
68
  boxColor(screen, pX1, pY1, pX2, pY2-1, mColors[pC]);
69
}
70
71
int GetXPosInPixels (int pPos)
72
{
73
  return  ( ( BOARD_POSITION - (BLOCK_SIZE * (BOARD_WIDTH / 2)) ) + (pPos * BLOCK_SIZE) );
74
}
75
76
int GetYPosInPixels (int pPos)
77
{
78
  return ( (screen->h - (BLOCK_SIZE * BOARD_HEIGHT)) + (pPos * BLOCK_SIZE) );
79
}
80
81
82
void DrawPiece (int pX, int pY, int pPiece, int pRotation)
83
{
84
  color mColor;        // Color of the block 
85
86
  // Obtain the position in pixel in the screen of the block we want to draw
87
  int mPixelsX = GetXPosInPixels (pX);
88
  int mPixelsY = GetYPosInPixels (pY);
89
90
  // Travel the matrix of blocks of the piece and draw the blocks that are filled
91
  for (int i = 0; i < PIECE_BLOCKS; i++)
92
  {
93
    for (int j = 0; j < PIECE_BLOCKS; j++)
94
    {
95
      
96
      if (GetBlockType(pPiece, pRotation, j, i) != 0)
97
        DrawRectangle(mPixelsX + i * BLOCK_SIZE, 
98
                mPixelsY + j * BLOCK_SIZE, 
99
               (mPixelsX + i * BLOCK_SIZE) + BLOCK_SIZE - 1, 
100
               (mPixelsY + j * BLOCK_SIZE) + BLOCK_SIZE - 1, 
101
                mColor);
102
    }
103
  }
104
}
105
106
int main(int argc, char **argv)
107
{
108
....
109
}

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Der erste Fehler ist trivial. In Deiner Funktion DrawPiece verwendest 
Du eine Variable namens mColor, hast ihr aber nie einen Wert zugewiesen. 
Da steht also zufälliger Kram drin.

Das entscheidende Problem ist Fehler Nummer 2:

> Fehler  2  error LNK2019: Verweis auf nicht aufgelöstes externes
> Symbol "__imp__boxColor" in Funktion ""void __cdecl
> DrawRectangle(int,int,int,int,enum color)"


Deine Funktion DrawRectangle verwendet ein Symbol "__imp__boxColor", 
und das ist nicht da, d.h. in keiner von Dir angegebenen Library 
enthalten.

Der Name lässt darauf schließen, daß das ein Symbol aus einer 
sogenannten Importlibrary ist, die dazu dient, Funktionen aus einer 
DLL verwenden zu können.

Und wenn man sich DrawRectangle ansieht, dann wird da auch tatsächlich 
boxColor verwendet. Offensichtlich ist das in irgendeiner Headerdatei 
ausreichend deklariert (sonst gäbe es andere Fehlermeldungen), aber die 
Library, in der es definiert ist, die fehlt halt noch.


Fehler 3 ist die Folge von Fehler 1.

Du solltest lernen, mit Deinem Werkzeug umzugehen. Das ist ein 
alltägliches Brot-und-Butter-Problem, das es beim Umgang mit jedem 
C/C++-Compiler geben kann.

von Jean P. (fubu1000)


Lesenswert?

So erstmal das für Win32:
http://pgdc.purdue.org/sdltutorial/sdl_setup.html

Zudem wenn deine SDL installation in deinem Visual Studio Verzeichniss 
liegt:
#include <SDL.h>

Gruß, falls nit klappt. Kann ich gerne moin auf der Arbeit mal schaun 
wie ich das gemacht hatte. Alleridngs unter Borland Builder 6.0 ^^.

P.S: Haste Multithreaded DLL aktiviert ??

N8

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

Das Einbinden der richtigen Headerdatei ist hier nicht das Problem, 
hier fehlt das Einbinden der richtigen Library.

von Jean P. (fubu1000)


Lesenswert?

Jo hast Recht Rufus hätte die Fehlermeldung 2 mal langsamer überfliegen 
sollen.
Gruß

Beitrag #5787345 wurde von einem Moderator gelöscht.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.