Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: sanxez1 en 2 Septiembre 2016, 16:17 pm



Título: aiudaaa!!!
Publicado por: sanxez1 en 2 Septiembre 2016, 16:17 pm
Llevo toda la mañana tratando soluconar el siguiente error: id returned 1 ext status
                                                                      undefined reference to `WinMain@16' (utilizo dev c++)

Utilizo el compilador TMD-GCC 4.9.2 32-BIT RELEASE

este es el codigo que trato de compilar:
Código:
#include <stdio.h>
#include <stdlib.h>
#include <allegro.h>
#include <iostream>

int iniciar();
void realizar_juego();
void terminar();

int iniciar(){
allegro_init();
install_keyboard();
set_color_depth(16);
if (set_gfx_mode(GFX_AUTODETECT,640,480,0,0)<0){
printf("error al iniciar el modo grafico\n");
allegro_exit();
exit(-1);
}
}

void terminar(){
allegro_exit();
}
int main(){
iniciar();
realizar_juego();
terminar();
}
void realizar_juego(){

BITMAP *nave;
PALETTE paleta;
int x,y, x_anterior, y_anterior;
BITMAP * buffer;


nave=load_bitmap("C:/Users/DANIEL/Desktop/Programación/C++/Allegro/Naves/recursos/nave.pcx", paleta);
set_palette(paleta);
if (nave==NULL) terminar();
buffer=create_bitmap(nave->w,nave->h);
clear (buffer);
if (buffer==NULL) terminar();
x=SCREEN_W/2;
y=SCREEN_H/2;

while (!key[KEY_ESC]){

if (key[KEY_UP,KEY_W])
y--;
if (key[KEY_DOWN,KEY_S])
y++;
if (key[KEY_LEFT,KEY_A])
x--;
if (key[KEY_RIGHT,KEY_D])
x++;

if (x<0) x=x_anterior;
if (x>SCREEN_W-nave->w) x=x_anterior;
if (y<0) y=y_anterior;
if (y>SCREEN_H-nave->h) y=y_anterior;
if ((x_anterior!=x) || (y_anterior!=y)){
blit (buffer,screen, 0, 0, x_anterior, y_anterior,buffer->w,buffer->h);
blit (screen,buffer,x,y,0,0,buffer->w,buffer->h);
draw_sprite(screen,nave, x, y);
}
x_anterior=x;
y_anterior=y;


}
}
gracias!!


Título: Re: aiudaaa!!!
Publicado por: AlbertoBSD en 2 Septiembre 2016, 16:22 pm
Hola ya vi tu error, no tienes una funcion Principal definida.

tienes que tener:

Código
  1. int main(){
  2. //llamar a tus funciones aqui.
  3. }

Saludos!


Título: Re: aiudaaa!!!
Publicado por: sanxez1 en 2 Septiembre 2016, 16:25 pm
me sigue saliendo el mismo error...


Título: Re: aiudaaa!!!
Publicado por: JonaLamper en 2 Septiembre 2016, 18:07 pm
¿Dónde has declarado el main? Debería ser algo así:

Código
  1. // Supongamos que aquí empieza tu fichero
  2.  
  3. // Aquí incluyes tus librerías
  4. using namespace std; // Yo suelo usar el espacio de nombres y lo pongo justo a continuación de las librerías
  5.  
  6. // Aquí implementas todas tus funciones como por ejemplo: terminar(), realizar_juego(), etc
  7.  
  8. // Y aquí abajo es donde tienes que poner el main
  9. int main(){
  10.   // Aquí llamas a tus funciones, como te dijo Alberto
  11.   return 0;
  12. }
  13.  

Otra opción es declarar los prototipos de las funciones arriba, después implementar la función main y después implementar tus funciones (eso quizá estaría mejor), pero si así te sirve también está bien.


Título: Re: aiudaaa!!!
Publicado por: dato000 en 2 Septiembre 2016, 21:26 pm
Como dijeron arriba, falta un main, además, no confies en Dev-C++, hace mucho tiempo dejo de recibir soporte, por lo que nada raro tenga problemas de compatibilidad con cualquier cosa.

Usa Codeblocks.

Nunca hay que olvidar lo básico en la estructura de lenguaje en programación, en el caso de c++:

Código
  1. #include <iostream.h>
  2.  
  3. using namespace std;
  4.  
  5. main()
  6. {
  7.    cout << "Hello World!";
  8.    return 0;
  9. }


Título: Re: aiudaaa!!!
Publicado por: sanxez1 en 3 Septiembre 2016, 14:14 pm
me sigue saliendo lo mismo


Título: Re: aiudaaa!!!
Publicado por: MAFUS en 4 Septiembre 2016, 04:06 am
Inserta la macro END_OF_MAIN() justo después de la función main():
Código
  1. // ... CÓDIGO
  2. int main() {
  3.    // ... CÓDIGO
  4. }
  5. END_OF_MAIN()
  6. // ... CÓDIGO


Título: Re: aiudaaa!!!
Publicado por: sanxez1 en 4 Septiembre 2016, 11:40 am
Muchísimas gracias a todos, ya funciona!!


Título: Re: aiudaaa!!!
Publicado por: Evox4 en 5 Septiembre 2016, 00:05 am
y cual fue el error?


Título: Re: aiudaaa!!!
Publicado por: sanxez1 en 5 Septiembre 2016, 00:21 am
Después de modificar el código funcionó.