Różne kody pod różnymi IDE

0

Witam:)
Mam taki mały problem : Zainstalowałem sobie ostatnio Netbeans i podpiopłem sobie pod nie Mingwa. Mam też drugie ide Code::Blocks. Mój problem jest następujący: Krótki przykładowy kod działa jeżeli kompiluje go pod Code::Blocks, a nie działa pod Netbeans. I nie za bardzo wiem czemu i nie wiem jak to zmienic ? :/
Kod działający pod Code::Blocks

#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif

int main ( int argc, char** argv )
{
    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    // create a new window
    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
                                           SDL_HWSURFACE|SDL_DOUBLEBUF);
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

    // load an image
    SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
    if (!bmp)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }

    // centre the bitmap on screen
    SDL_Rect dstrect;
    dstrect.x = (screen->w - bmp->w) / 2;
    dstrect.y = (screen->h - bmp->h) / 2;

    // program main loop
    bool done = false;
    while (!done)
    {
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = true;
                    break;
                }
            } // end switch
        } // end of message processing

        // DRAWING STARTS HERE

        // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

        // draw bitmap
        SDL_BlitSurface(bmp, 0, screen, &dstrect);

        // DRAWING ENDS HERE

        // finally, update the screen :)
        SDL_Flip(screen);
    } // end main loop

    // free loaded bitmap
    SDL_FreeSurface(bmp);

    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}

Kode działający pod Netbeans :

//#ifdef __cplusplus
   #include <cstdlib>
//#else
    //#include <stdlib.h>
//#/endif
//#ifdef __APPLE__
//#include <SDL/SDL.h>
//#else
#include <SDL.h>
//#endif
#include <windows.h>


//int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int)
{
    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    // create a new window
    SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
                                           SDL_HWSURFACE|SDL_DOUBLEBUF);
    if ( !screen )
    {
        printf("Unable to set 640x480 video: %s\n", SDL_GetError());
        return 1;
    }

    // load an image
    SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
    if (!bmp)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }

    // centre the bitmap on screen
    SDL_Rect dstrect;
    dstrect.x = (screen->w - bmp->w) / 2;
    dstrect.y = (screen->h - bmp->h) / 2;
    
    // program main loop
    bool done = false;
    while (!done)
    {
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            // check for messages
            switch (event.type)
            {
                // exit if the window is closed
            case SDL_QUIT:
                done = true;
                break;

                // check for keypresses
            case SDL_KEYDOWN:
                {
                    // exit if ESCAPE is pressed
                    if (event.key.keysym.sym == SDLK_ESCAPE)
                        done = true;
                    break;
                }
            } // end switch
        } // end of message processing

        // DRAWING STARTS HERE

        // clear screen
        SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));

        // draw bitmap
        SDL_BlitSurface(bmp, 0, screen, &dstrect);

        // DRAWING ENDS HERE

        // finally, update the screen :)
        SDL_Flip(screen);
    } // end main loop

    // free loaded bitmap
    SDL_FreeSurface(bmp);

    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}

Dlaczego ten pierwszy kod nie działa pod Netbeans jak korzysta on z tego samego kompilatora co CodeBlocks ?

0

Bo pewnie sa bledy. Jakie? Wszystko opisuje pewnie kompilator/linker. Ale sie nie podzieliles informacjami z logu.

0

Przepraszam :) Zapomniałem
Log z NetBeans :

Running "C:\msys\1.0\bin\make.exe  -f Makefile CONF=SDL" in C:\Users\piotrek\Documents\NetBeansProjects\SDLProba2

/usr/bin/make -f nbproject/Makefile-SDL.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/piotrek/Documents/NetBeansProjects/SDLProba2'
/usr/bin/make  -f nbproject/Makefile-SDL.mk dist/SDL/MinGW_1-Windows/sdlproba2.exe
make[2]: Entering directory `/c/Users/piotrek/Documents/NetBeansProjects/SDLProba2'
mkdir -p dist/SDL/MinGW_1-Windows
mingw32-g++.exe -o dist/SDL/MinGW_1-Windows/sdlproba2 build/SDL/MinGW_1-Windows/main.o -lSDL -lSDLmain 
/mingw/lib/libmingw32.a(main.o):main.c:(.text+0xbd): undefined reference to `WinMain@16'

collect2: ld returned 1 exit status

make[2]: *** [dist/SDL/MinGW_1-Windows/sdlproba2.exe] Error 1
make[2]: Leaving directory `/c/Users/piotrek/Documents/NetBeansProjects/SDLProba2'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/Users/piotrek/Documents/NetBeansProjects/SDLProba2'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.

0

W netbeans odpalasz projekt aplikacji windows, nie konsolowej...

0

Dzieki :)
Tylko gdzie takie coś można ustawić w netbeans ? Bo przegrzebałem prawie całe i nie mogę znaleźć ;/

0

Nie wiem, nie uzywalem. Moze ktos inny bedzie wiedzial.

1 użytkowników online, w tym zalogowanych: 0, gości: 1