Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

int main() not found, but it's there

Status
Not open for further replies.

Ninkazu

Programmer
Mar 29, 2003
12
US
I'm just starting to do SDL in C++, and I wrote a program to test it out, and basically it plots a big spray of particles on the screen. The problem I'm having is an external error in compilation saying int main() doesn't exist, when it's clearly there. Please help, because it's driving me nuts!

Here's my code:
----------------------------------------------------------
#include "SDL.h"
#include "SDL_keysym.h"

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

void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
{
Uint32 color = SDL_MapRGB(screen->format, r,g,b);
Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}

struct Cstar
{
double vx, vy, x, y;
};

int main()
{
SDL_Surface *screen;
bool done= false;
SDL_Event event;
const MaxStars = 1000;
Cstar stars[MaxStars];

if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf(&quot;Unable to init SDL: %s\n&quot;, SDL_GetError());
return 1;
}
atexit(SDL_Quit);

screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
if (!screen)
{
printf(&quot;Unable to init SDL: %s\n&quot;, SDL_GetError());
return 1;
}
int i;
double cx, cy;
i=0;
for (i=0; i<=MaxStars; i++)
{
stars.x = (double) (160 + (rand()%40)*((rand()%3)-1));
stars.y = (double) (rand()%20 + 1);
stars.vx = (double) (((rand()%3)-1)*((rand()%6)+1)*sin(rand()%360));
stars.vx = (double) (((rand()%3)-1)*((rand()%6)+1)*cos(rand()%360));
}

do
{
//particles
if(SDL_QuitRequested())
done = true;

SDL_LockSurface(screen);
i=0;
for (i=0; i<=MaxStars; i++)
{
beginupdate:
cx = stars.x + stars.vx;
cy = stars.y + stars.vy;

if(cx < 1 || cx > 638){
stars.vx = -stars.vx;
cx = stars.x + stars.vx;
}
if (cy < 1){
stars.vy = -stars.vy;
cy = stars.y + stars.vy;
}
if (cy > 478){
stars.x = (double) (160 + (rand()%40)*((rand()%3)-1));
stars.y = (double) (rand()%20 + 1);
stars.vx = (double) (((rand()%3)-1)*((rand()%6)+1)*sin(rand()%360));
stars.vx = (double) (((rand()%3)-1)*((rand()%6)+1)*cos(rand()%360));
goto beginupdate;
}
stars.x = cx;
stars.y = cy;
stars.vy = stars.vy + .28;
DrawPixel(screen, (int)cx, (int)cy, 255,255,255);
}
SDL_UnlockSurface(screen);

SDL_Flip(screen); //PUT (0, 0), buffer, PSET

if( SDL_PollEvent( &event ) ){
switch( event.type ){
case SDL_KEYDOWN:
switch(event.key.keysym.sym ){
case SDLK_ESCAPE:
done = true;
break;
default:
break;
}
default:
break;
}
}
}while (!done);

return 0;
}

-----------------------
Soon to come - a QBasic contest forum!
-----------------------
 
>> when it's clearly there

Yes it is. When receiving an error message, particularly a compile error message you should post it so we can see it.

Assuming you are correct that would pretty much only leave a project setting issue as the solution.

-pete

 
Here's my error message:
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Algebra.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

-----------------------
Soon to come - a QBasic contest forum!
-----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top