Strange error in visual c 6 when linking

Any help in solving the fix to this problem would be greatly appreacated.-----
Linking…
main.obj : error LNK2001: unresolved external symbol “void __cdecl
DrawPixel(struct SDL_Surface *,int,int,unsigned char,unsigned char,unsigned
char)” (?DrawPixel@@YAXPAUSDL_Surface@@HHEEE at Z)
Debug/SDL Tests.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

SDL Tests.exe - 2 error(s), 0 warning(s)

Source Code:

#include <stdio.h>
#include <stdlib.h>

#include <SDL.h>

// The functions are not shown to save space
void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B);
void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}

int main(int argc, char *argv[])
{

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

SDL_Surface *screen;
screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( screen == NULL )
{
printf(“Unable to set 640x480 video: %s\n”, SDL_GetError());
exit(1);
}

// DRAWING GOES HERE
Slock(screen);
for(int x=0;x<640;x++)
{
for(int y=0;y<480;y++)
{
DrawPixel(screen, x,y,y/2,y/2,x/3);
}
}
Sulock(screen);
SDL_Flip(screen);

return 0;
}


Jeffrey D. Means
CIO For MeansPC
@Jeff_Means

Jeff Means wrote:

// The functions are not shown to save space
void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B);

What does this comment mean? It says functions (ie. plural) but the
following 2 functions are indeed defined fully below, whereas DrawPixel
is not. Forgetting to provide a function body for DrawPixel would give
you the error you currently see. If DrawPixel is in another file, make
sure that file is included in the project (or makefile).–
Kylotan
http://pages.eidosnet.co.uk/kylotan

The error message means that the linker was unable to find
a function called ?DrawPixel@@YAXPAUSDL_Surface@@HHEEE at Z
which is the C++ decorated name for the missing body
of your function DrawPixel().

Your code is being interpreted as C++ because your file name is
(probably) ‘main.cpp’.

If the function body does exist in another file, make sure it
is C++ style also e.g. ‘draw.cpp’, or declare the prototype in
a header file like this:

#ifdef __cplusplus
extern “C” {
#endif

extern void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B);

#ifdef __cplusplus
}
#endif

to prevent the C++ name decoration,

cheers,
John.> ----- Original Message -----

From: kylotan@kylotan.eidosnet.co.uk (Kylotan)
To:
Sent: Monday, November 25, 2002 2:13 AM
Subject: Re: [SDL] strange error in visual c 6 when linking

Jeff Means wrote:

// The functions are not shown to save space
void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B);

What does this comment mean? It says functions (ie. plural) but the
following 2 functions are indeed defined fully below, whereas DrawPixel
is not. Forgetting to provide a function body for DrawPixel would give
you the error you currently see. If DrawPixel is in another file, make
sure that file is included in the project (or makefile).


Kylotan
http://pages.eidosnet.co.uk/kylotan


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi,

I’m not quite shure about this, but I think this is a very commen error using
SDL with Visual C++. You have to change the “Code-Generation” in your
project’s properties window to “Multithreaded-DLL”.

hope this helps.> Any help in solving the fix to this problem would be greatly appreacated.


Linking…
main.obj : error LNK2001: unresolved external symbol “void __cdecl
DrawPixel(struct SDL_Surface *,int,int,unsigned char,unsigned char,unsigned
char)” (?DrawPixel@@YAXPAUSDL_Surface@@HHEEE at Z)
Debug/SDL Tests.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

SDL Tests.exe - 2 error(s), 0 warning(s)

Source Code:

#include <stdio.h>
#include <stdlib.h>

#include <SDL.h>

// The functions are not shown to save space
void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G, Uint8 B);
void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}

int main(int argc, char *argv[])
{

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

SDL_Surface *screen;
screen=SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( screen == NULL )
{
printf(“Unable to set 640x480 video: %s\n”, SDL_GetError());
exit(1);
}

// DRAWING GOES HERE
Slock(screen);
for(int x=0;x<640;x++)
{
for(int y=0;y<480;y++)
{
DrawPixel(screen, x,y,y/2,y/2,x/3);
}
}
Sulock(screen);
SDL_Flip(screen);

return 0;
}


Jeffrey D. Means
CIO For MeansPC
meaje at meanspc.com


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Alexander Lauser