Author Topic: CC can not correctly judge the right include files  (Read 12960 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
CC can not correctly judge the right include files
« on: January 08, 2010, 01:22:09 pm »
This example comes from SDL wizard.  CC can not be smart prompt anything.
Code
#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;
}

but if change this code from:
Code
#ifdef __cplusplus
    #include <cstdlib>
#else
    #include <stdlib.h>
#endif
#ifdef __APPLE__
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
TO:
Code
#include <SDL.h>
It's work fine!
Complete code:
Code
#include <SDL.h>

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;
}

[attachment deleted by admin]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: CC can not correctly judge the right include files
« Reply #1 on: January 08, 2010, 01:25:01 pm »
Since many system header file that contains all the conditions, I think it is likely that CC is not a comprehensive analysis of one of the reasons.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9693
Re: CC can not correctly judge the right include files
« Reply #2 on: January 08, 2010, 01:45:50 pm »
CC does only use the first pre-processor in #ifdef statements. If you search through the forums you'll realise that handling of pre-processors is not an easy task and done in a simple way in CC.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline blueshake

  • Regular
  • ***
  • Posts: 458
Re: CC can not correctly judge the right include files
« Reply #3 on: January 09, 2010, 01:41:57 am »
One way to solve this is adding the parse path to the parser option manually.
[meunu]project->properties->c/c++ parser options.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: CC can not correctly judge the right include files
« Reply #4 on: January 09, 2010, 02:53:08 am »
CC does only use the first pre-processor in #ifdef statements. If you search through the forums you'll realise that handling of pre-processors is not an easy task and done in a simple way in CC.
Because in the system header file, the conditions contained in the situation too much.
Although there are technical difficulty, but if not properly judge, CC is difficult to achieve the desired results.
In my humble and willing to please CC the team on this issue to find ways to find an ideal solution.
Thanks!

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: CC can not correctly judge the right include files
« Reply #5 on: January 09, 2010, 02:54:19 am »
One way to solve this is adding the parse path to the parser option manually.
[meunu]project->properties->c/c++ parser options.
Has nothing to do with this option, even if I add the search path, we can not search for header files needed.

Offline blueshake

  • Regular
  • ***
  • Posts: 458
Re: CC can not correctly judge the right include files
« Reply #6 on: January 09, 2010, 03:52:33 am »
Need to reopen the project after you set it.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline blueshake

  • Regular
  • ***
  • Posts: 458
Re: CC can not correctly judge the right include files
« Reply #7 on: January 09, 2010, 03:55:20 am »
or you can try this.(as I know,it use scrip language.it will slow down parse speed.http://forums.codeblocks.org/index.php/topic,11377.0.html
« Last Edit: January 09, 2010, 04:40:23 am by blueshake »
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?