Can't find <iostream>

This is a discussion on Can't find <iostream> within the C++ Programming forums, part of the General Programming Boards category; Hello there, I've been running in to a ton of problems lately. I'm in Vocational school, and I use Ubuntu ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    17

    Can't find <iostream>

    Hello there,
    I've been running in to a ton of problems lately. I'm in Vocational school, and I use Ubuntu on my computer there. I've been programming with the allegro library, and things were going fine. Then, when I went to compile a program I was making (a Pong game), Code::Blocks told me it couldn't find <iostream> and <string>. I compiled something like 10 minutes before that, and didn't do anything.

    I went home, and tried the code on my Ubuntu on my laptop and I got the same problem. So I figured it as the code, and I wrote a simple hello world program to test my iostream. It didn't work. Here're the errors I got:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void){
        cout << "Hello world!";
        cin.get();
    
        return 0;
    }
    Errors:

    Code:
    /usr/include/c++/4.3.3/iostream|44|error: bits/c++config.h: No such file or directory|
    /usr/include/c++/4.3.3/bits/stringfwd.h||In function ‘_GLIBCXX_BEGIN_NAMESPACE’:|
    /usr/include/c++/4.3.3/bits/stringfwd.h|48|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|51|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|54|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|58|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|60|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/stringfwd.h|68|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/lib/gcc/i486-linux-gnu/4.3.3/include/stddef.h|214|error: storage class specified for parameter ‘size_t’|
    /usr/lib/gcc/i486-linux-gnu/4.3.3/include/stddef.h|326|error: storage class specified for parameter ‘wchar_t’|
    /usr/include/c++/4.3.3/cstddef|54|error: expected declaration specifiers before ‘_GLIBCXX_BEGIN_NAMESPACE’|
    /usr/include/c++/4.3.3/cstddef|57|error: expected declaration specifiers before ‘using’|
    /usr/include/c++/4.3.3/cstddef|59|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/cwchar|70|error: expected declaration specifiers before ‘_GLIBCXX_BEGIN_NAMESPACE’|
    /usr/include/c++/4.3.3/cwchar|74|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/bits/postypes.h|77|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘streamsize’|
    /usr/include/c++/4.3.3/bits/postypes.h|90|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|186|error: expected declaration specifiers before ‘;’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|193|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|198|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|207|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|209|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|211|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/iosfwd|54|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|57|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|60|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|63|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|66|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|70|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|74|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|78|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|82|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|85|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|88|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|91|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|94|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|97|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|102|error: expected declaration specifiers before ‘class’|
    /usr/include/c++/4.3.3/iosfwd|132|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|133|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|134|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|135|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|136|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|137|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|138|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|139|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|140|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|141|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|142|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|143|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/iosfwd|144|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    ||More errors follow but not being shown.|
    ||Edit the max errors limit in compiler options...|
    ||=== Build finished: 50 errors, 0 warnings ===|
    when I compile the code for the Pong game I was making (I know there are bugs, I just wanted to compile and see if it would show the paddles -- I found out there are htings I need to fix before it works, but look at everything else)

    Code:
    #include <allegro.h>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void Check_Null(BITMAP* Picture, string Type, string Error);
    int Get_Rand(void);
    
    int main(void){
        cout << "This is a Pong game by Lorgon Jortle. Mar 31, 2009.\n";
        cin.get();
    
        allegro_init();
        install_keyboard();
    
        /**Declare variables**/
    
        //Bitmaps
        BITMAP* buffer = NULL;
        BITMAP* player1 = NULL;
        BITMAP* player2 = NULL;
        BITMAP* ball = NULL;
    
        //Integers
        int player1_x, player1_y, player2_x, player2_y;
        int ball_x, ball_y;
        int ball_speed, ball_direction; //Ball direction 1 = left, 2 = left up, 3 = left down, 4 = right, 5 = right up, 6 = right down
    
        int player1_bb, player2_bb; //The line on the side of the paddle to check for collisions
    
        //Booleans
        bool Collision = false;
    
        /**Assign variables**/
    
        //Integers
        player1_x = 0;
        player1_y = 240;
        player2_x = 640;
        player2_y = 240;
    
        ball_speed = 2;
    
        //Bitmaps
        buffer = create_bitmap(640, 480);
        Check_Null(buffer, "buffer". "buffer failed to load.");
    
        player1 = load_bitmap("player1.bmp", NULL);
        Check_Null(player1, "player1.bmp", "player1.bmp failed to load.");
    
        player2 = load_bitmap("player2.bmp", NULL);
        Check_Null(player2, "player2.bmp", "player2.bmp failed to load.");
    
        ball = load_bitmap("ball.bmp", NULL);
        Check_Null(ball, "ball.bmp", "ball.bmp", "failed to load.");
    
        while(!key[KEY_ESC]){
            //Draw the ball
    
    
            //Accept input
            if(key[KEY_UP]){
                player2_y += 3;
            }
            if(key[KEY_DOWN]){
                player2_y -= 3;
            }
            if(key[KEY_W]){
                player1_y += 3;
            }
            if(key[KEY_S]){
                player1_y -= 3;
            }
            /*
    
            LEAVE ROOM FOR FURTHER KEY PRESSES
    
            */
    
    
    
            draw_sprite(buffer, player1, player1_x, player1_y);
            draw_sprite(buffer, player2, player2_x, player2_y);
            draw_sprite(buffer, ball, ball_x, ball_y);
            blit(buffer, screen, 0, 0, 640, 480);
            clear_bitmap(buffer);
        }
    
        destroy_bitmap(buffer);
        destroy_bitmap(player1);
        destroy_bitmap(player2);
        destroy_bitmap(ball);
    
        return 0;
    }
    END_OF_MAIN();
    
    void Check_Null(BITMAP* Picture, string Type, string Error){
        if(Picture == NULL){
            cout << "Error: " << Error << endl;
        }
        else if(Picture != NULL){
            cout << Type << " loaded successfully.\n";
        }
    }
    END_OF_FUNCTION(Check_Null);
    Here are my errors:

    Code:
    /usr/include/bits/stdlib.h|21|error: #error "Never include <bits/stdlib.h> directly; use <stdlib.h> instead."|
    /usr/include/bits/string.h|21|error: #error "Never use <bits/string.h> directly; include <string.h> instead."|
    /usr/include/bits/fcntl.h|21|error: #error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."|
    /usr/include/bits/endian.h|4|error: #error "Never use <bits/endian.h> directly; include <endian.h> instead."|
    /usr/include/bits/unistd.h|21|error: #error "Never include <bits/unistd.h> directly; use <unistd.h> instead."|
    /usr/include/allegro/file.h|43|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘file_time’|
    /usr/include/allegro/file.h|52|error: expected specifier-qualifier-list before ‘time_t’|
    /usr/include/allegro/platform/al386gcc.h||In function ‘fixadd’:|
    /usr/include/allegro/platform/al386gcc.h|133|error: ‘ERANGE’ undeclared (first use in this function)|
    /usr/include/allegro/platform/al386gcc.h|133|error: (Each undeclared identifier is reported only once|
    /usr/include/allegro/platform/al386gcc.h|133|error: for each function it appears in.)|
    /usr/include/allegro/platform/al386gcc.h||In function ‘fixsub’:|
    /usr/include/allegro/platform/al386gcc.h|171|error: ‘ERANGE’ undeclared (first use in this function)|
    /usr/include/allegro/platform/al386gcc.h||In function ‘fixmul’:|
    /usr/include/allegro/platform/al386gcc.h|209|error: ‘ERANGE’ undeclared (first use in this function)|
    /usr/include/allegro/platform/al386gcc.h||In function ‘fixdiv’:|
    /usr/include/allegro/platform/al386gcc.h|261|error: ‘ERANGE’ undeclared (first use in this function)|
    /usr/include/allegro/platform/al386gcc.h||In function ‘fixceil’:|
    /usr/include/allegro/platform/al386gcc.h|366|error: ‘ERANGE’ undeclared (first use in this function)|
    /usr/include/allegro/inline/fmaths.inl||In function ‘ftofix’:|
    /usr/include/allegro/inline/fmaths.inl|32|error: ‘ERANGE’ undeclared (first use in this function)|
    /usr/include/allegro/inline/fmaths.inl||In function ‘fixacos’:|
    /usr/include/allegro/inline/fmaths.inl|211|error: ‘EDOM’ undeclared (first use in this function)|
    /usr/include/allegro/inline/fmaths.inl||In function ‘fixasin’:|
    /usr/include/allegro/inline/fmaths.inl|222|error: ‘EDOM’ undeclared (first use in this function)|
    /usr/include/c++/4.3.3/iostream|44|error: bits/c++config.h: No such file or directory|
    /usr/include/c++/4.3.3/bits/stringfwd.h||In function ‘_GLIBCXX_BEGIN_NAMESPACE’:|
    /usr/include/c++/4.3.3/bits/stringfwd.h|48|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|51|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|54|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|58|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|60|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/stringfwd.h|68|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/cstddef|57|error: expected declaration specifiers before ‘using’|
    /usr/include/c++/4.3.3/cstddef|59|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/cwchar|70|error: expected declaration specifiers before ‘_GLIBCXX_BEGIN_NAMESPACE’|
    /usr/include/c++/4.3.3/cwchar|74|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/bits/postypes.h|77|error: storage class specified for parameter ‘streamsize’|
    /usr/include/c++/4.3.3/bits/postypes.h|90|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|186|error: expected declaration specifiers before ‘;’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|193|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|198|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|207|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|209|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|211|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/iosfwd|54|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|57|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|60|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|63|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|66|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|70|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|74|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|78|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|82|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|85|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|88|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|91|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|94|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|97|error: expected declaration specifiers before ‘template’|
    ||More errors follow but not being shown.|
    ||Edit the max errors limit in compiler options...|
    ||=== Build finished: 50 errors, 0 warnings ===|
    I have uninstalled Code::Blocks, gcc, g++, and tried installing other IDE's. Now I reinstalled gcc, g++ and Code::Blocks and it's still giving me errors.

    Anybody have any ideas? I have the latest build-essential, and release.

    Lorgon Jortle

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Well, you do have <iostream> because line 44 of that file is
    Code:
    #include <bits/c++config.h>
    and line 48 is the function call
    Code:
    _GLIBCXX_BEGIN_NAMESPACE(std)
    so it seems to be that "c++config.h" file that you can't seem to access. Do you have a /usr/include/c++/4.3/i486-linux-gnu/bits/c++config.h file?

    Lines 20-22 of /usr/include/bits/stdlib.h are
    Code:
    #ifndef _STDLIB_H
    # error "Never include <bits/stdlib.h> directly; use <stdlib.h> instead."
    #endif
    so it looks like something is inappropriately #including that file and generating those errors. Not that that helps you.

    I guess the next thing to try would be to "completely uninstall" build-essential and liballegro*** (whichever version you have), and reinstall them. (Assuming you installed an Ubuntu allegro package & didn't build it from source.)

    Another thought -- could it be something as simple as that somehow your $PATH got messed up?

  3. #3
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    /usr/include/c++/4.3.3/iostream|44|error: bits/c++config.h: No such file or directory|
    I think we all know a lot of times a 50 line compiler error is usally caused by the first line and then it just decays from there. your compiler obviously can't find that bits/c++config.h file so i would check your $PATH variable and make sure thats taken care of as well as making sure config.h isn't corrupted in some way. BTW bits/c++config.h: - Google Search google is still your best friend. check the first link and i bet you its related to your problem. cheers.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    17
    I've reinstalled gcc, g++, allegro, and code::blocks. Still the same problem. I've searched how to change the $PATH variable, but I still haven't found how. Will you please point me in the direction to do so, and not vaguely tell me "Google is my friend". I'm not ignorant, you know.

    EDIT: I completely removed build-essential, liballegro4.2, and gcc, then reinstalled them. I still get the same error about bits/stdlib.h and bits/string.h and so on. Any other ideas?
    Last edited by Lorgon Jortle; 04-01-2009 at 04:50 PM.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Does GCC work when called from the command line?

    Does a Hello World in CodeBlocks work?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    17
    Quote Originally Posted by CornedBee View Post
    Does GCC work when called from the command line?

    Does a Hello World in CodeBlocks work?
    Same errors doing gcc from terminal. The Hello World is the first one I showed up in post #1. I'll try a fresh hello world in Gedit, then try to compile it via terminal.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void){
    	cout << "Hello world, C++ works again.\n";
    	cin.ignore(1000, '\n');
    	cin.get();
    	
    	return 0;
    }
    Code:
    lorgonjortle@laptop:~/Desktop/Test$ ls
    main.c
    lorgonjortle@laptop:~/Desktop/Test$ gcc main.c
    main.c:1:20: error: iostream: No such file or directory
    main.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
    main.c: In function ‘main’:
    main.c:6: error: ‘cout’ undeclared (first use in this function)
    main.c:6: error: (Each undeclared identifier is reported only once
    main.c:6: error: for each function it appears in.)
    main.c:7: error: ‘cin’ undeclared (first use in this function)
    lorgonjortle@laptop:~/Desktop/Test$ g++ main.c
    lorgonjortle@laptop:~/Desktop/Test$ ./a.out
    Hello world, C++ works again.
    
    
    lorgonjortle@laptop:~/Desktop/Test$
    CRAZY! It worked when I did g++, but not gcc. Even when the code was main.c not .cpp. Let me try to compile the allegro stuff with g++....

    EDIT: When I did it with g++, it compiled fine. This is the command I used:
    Code:
    g++ Collision.c `allegro-config --cflags` `allegro-config --libs`
    Here was the code:

    Code:
    #include <iostream>
    #include <allegro.h>
    #include <string>
    
    using namespace std;
    
    
    bool Collision_Test(void); //Checks for collision
    void Check_Null(BITMAP* Test, string Type, string Error); //Tests bitmap to see if it recieved content
    
    int main(void){
        cout << "Collision testing in preparation for Pong. Mar 30, 2009\nLorgon Jortle\n";
        cin.get();
        //system("clear");
    
        allegro_init();
        install_keyboard();
        set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);  //Previous three set up everything
        /**Create variables**/
    
        //Bitmaps
        BITMAP* image1 = NULL;
        BITMAP* image2 = NULL;
        BITMAP* buffer = NULL;
    
        //Integers
        int image1_x, image2_x;
        int image1_y, image2_y;
    
        //Bounding boxes
        int image1_bb_top, image1_bb_bottom, image1_bb_right, image1_bb_left;
        int image2_bb_top, image2_bb_bottom, image2_bb_right, image2_bb_left;
    
        //Booleans
        bool Show_Box = false; //Whether or not to show the bounding box
        bool Collision = false;
    
        /**Assign variables**/
    
        //Bitmaps
        image1 = load_bitmap("image1.bmp", NULL);
        Check_Null(image1, "image1.bmp", "image1.bmp failed to load");
    
        image2 = load_bitmap("image2.bmp", NULL);
        Check_Null(image2, "image2.bmp", "image2.bmp failed to load");
    
        buffer = create_bitmap(640, 480);
        Check_Null(buffer, "buffer", "buffer creation failed");
    
        //Integers
        image1_x = 400;
        image1_y = 300;
    
        image2_x = 200;
        image2_y = 200;
    
        image1_bb_top = image1_x;
        image1_bb_bottom = (image1_bb_top + image1->h);
        image1_bb_left = image1_y;
        image1_bb_right = (image1_y + image1->w);
                                                                //These set the positions of the lines
        image2_bb_top = image2_x;
        image2_bb_bottom = (image2_bb_top + image2->h);
        image2_bb_left = image2_y;
        image2_bb_right = (image2_bb_left + image2->w);
    
    
        while(!key[KEY_ESC]){ //Run loop while the escape key isn't pressed
            if(key[KEY_UP]){
                image1_y -= 3;
            }
            if(key[KEY_DOWN]){
                image1_y += 3;
            }
            if(key[KEY_LEFT]){
                image1_x -= 3;
            }
            if(key[KEY_RIGHT]){
                image1_x += 3;
            }
            if(key[KEY_W]){
                image2_y -= 3;
            }
            if(key[KEY_S]){
                image2_y += 3;
            }
            if(key[KEY_A]){
                image2_x -= 3;
            }
            if(key[KEY_D]){
                image2_x += 3;
            }
            if(key[KEY_ENTER]){
                image1_x = 400;
                image1_y = 300;
                image2_x = 200;
                image2_y = 200;
            }
            if(key[KEY_SPACE]){
                Show_Box = true;
            }
            else if(!key[KEY_SPACE]){
                Show_Box = false;
            }
    
        Collision = true;
        //Check for collision
        if(image1_bb_bottom < image2_bb_top){
            Collision = false;
        }
        if(image1_bb_top > image2_bb_bottom){
            Collision = false;
        }
        if(image1_bb_left > image2_bb_right){
            Collision = false;
        }
        if(image1_bb_right < image2_bb_left){
            Collision = false;
        }
        if(Collision == true){
            textprintf_ex(buffer, font, 0,5, makecol(255,255,255), -1, "Collision detected!");
        }
    
        //Update the lines
        image1_bb_top = image1_y;
        image1_bb_bottom = (image1_bb_top + image1->h);
        image1_bb_left = image1_x;
        image1_bb_right = (image1_bb_left + image1->w);
                                                                //These set the positions of the lines
        image2_bb_top = image2_y;
        image2_bb_bottom = (image2_bb_top + image2->h);
        image2_bb_left = image2_x;
        image2_bb_right = (image2_bb_left + image2->w);
    
    
        //Draw what we have
        draw_sprite(buffer, image1, image1_x, image1_y);
        draw_sprite(buffer, image2, image2_x, image2_y);
    
        if(Show_Box == true){
            line(buffer, image1_bb_left, image1_bb_top, image1_bb_right, image1_bb_top, makecol(255, 0, 0));
            line(buffer, image1_bb_left, image1_bb_top, image1_bb_left, image1_bb_bottom, makecol(255, 0, 0));
            line(buffer, image1_bb_left, image1_bb_bottom, image1_bb_right, image1_bb_bottom, makecol(255, 0, 0));
            line(buffer, image1_bb_right, image1_bb_top, image1_bb_right, image1_bb_bottom, makecol(255, 0, 0));
    
            line(buffer, image2_bb_left, image2_bb_top, image2_bb_right, image2_bb_top, makecol(255, 0, 0));
            line(buffer, image2_bb_left, image2_bb_top, image2_bb_left, image2_bb_bottom, makecol(255, 0, 0));
            line(buffer, image2_bb_left, image2_bb_bottom, image2_bb_right, image2_bb_bottom, makecol(255, 0, 0));
            line(buffer, image2_bb_right, image2_bb_top, image2_bb_right, image2_bb_bottom, makecol(255, 0, 0));
        }
    
        blit(buffer, screen, 0, 0, 0, 0, 640, 480);
        clear_bitmap(buffer);
    
        }
    
        destroy_bitmap(image1);
        destroy_bitmap(image2);
        destroy_bitmap(buffer);
    
        cout << "\n\nGame played successfully!\n";
    
        return 0;
    }
    END_OF_MAIN();
    
    void Check_Null(BITMAP* Test, string Type, string Error){
        if(Test == NULL){
            cout << "Error: Bitmap NULL\nError report: " << Error << endl;
        }
        else if(Test != NULL){
            cout << Type << " loaded successfully.\n";
        }
    }
    END_OF_FUNCTION(Check_Null);
    So I'm just using Geany, and I compile via the built-in terminal inside of it. Thanks for the help, guys/gals.
    Last edited by Lorgon Jortle; 04-01-2009 at 08:18 PM.

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    CRAZY! It worked when I did g++, but not gcc. Even when the code was main.c not .cpp. Let me try to compile the allegro stuff with g++....

    EDIT: When I did it with g++, it compiled fine. This is the command I used:
    so just to clarify lorgon, you were compiling a C++ program as a C program is that right.

    for future reference C++ is supposed to be a superset of C (meaning it should compile pretty much any C code) as a valid C++ program. It doesn't do it very well, but it tries and i'm sure you'll get used to the ideosyncracies of both language especially when doing game coding like you are now. Many in the industry say C/C++ like its one language, but in fact they are two separate distinct languages. get used to that.

    BTW, allegro is written in C not C++, so writting C++ code with the allegro lib you should compile it as C++, not C. which means calling g++ not gcc.

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    From the errors that you posted in #6
    Code:
    lorgonjortle@laptop:~/Desktop/Test$ gcc main.c
    main.c:1:20: error: iostream: No such file or directory
    main.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
    main.c: In function ‘main’:
    main.c:6: error: ‘cout’ undeclared (first use in this function)
    main.c:6: error: (Each undeclared identifier is reported only once
    main.c:6: error: for each function it appears in.)
    main.c:7: error: ‘cin’ undeclared (first use in this function)
    it's obvious that the error is using the c compiler (and .c extension) on a file that includes <iostream>. But those are completely different from the errors you posted for your "Hello world" in #1:
    Code:
    /usr/include/c++/4.3.3/iostream|44|error: bits/c++config.h: No such file or directory|
    /usr/include/c++/4.3.3/bits/stringfwd.h||In function ‘_GLIBCXX_BEGIN_NAMESPACE’:|
    /usr/include/c++/4.3.3/bits/stringfwd.h|48|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|51|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|54|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|58|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/stringfwd.h|60|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/stringfwd.h|68|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/lib/gcc/i486-linux-gnu/4.3.3/include/stddef.h|214|error: storage class specified for parameter ‘size_t’|
    /usr/lib/gcc/i486-linux-gnu/4.3.3/include/stddef.h|326|error: storage class specified for parameter ‘wchar_t’|
    /usr/include/c++/4.3.3/cstddef|54|error: expected declaration specifiers before ‘_GLIBCXX_BEGIN_NAMESPACE’|
    /usr/include/c++/4.3.3/cstddef|57|error: expected declaration specifiers before ‘using’|
    /usr/include/c++/4.3.3/cstddef|59|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/cwchar|70|error: expected declaration specifiers before ‘_GLIBCXX_BEGIN_NAMESPACE’|
    /usr/include/c++/4.3.3/cwchar|74|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/bits/postypes.h|77|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘streamsize’|
    /usr/include/c++/4.3.3/bits/postypes.h|90|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|186|error: expected declaration specifiers before ‘;’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|193|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|198|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/bits/postypes.h|207|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|209|error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token|
    /usr/include/c++/4.3.3/bits/postypes.h|211|error: expected declaration specifiers before ‘_GLIBCXX_END_NAMESPACE’|
    /usr/include/c++/4.3.3/iosfwd|54|error: expected declaration specifiers before ‘template’|
    /usr/include/c++/4.3.3/iosfwd|57|error: expected declaration specifiers before ‘template’|
    ...
    so what did you do that produced those errors?

  9. #9
    Registered User
    Join Date
    Mar 2009
    Posts
    17
    The longer list was what Code::Blocks gave me. The shorter was when I did it via terminal. I understand now though, I was using C++ code, and I thought it had to be compiled as C. Thanks for the help. :-)

    It's just odd that it always worked before. Maybe it's the new upgrade that changed it so that wasn't allowed...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 10:13 AM
  2. could not find -lwsock32.lib
    By thomas_joyee in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 01:28 PM
  3. How to find O of threads ?
    By jabka in forum C Programming
    Replies: 3
    Last Post: 03-11-2008, 01:25 PM
  4. how do u find 2nd largest number??
    By juancardenas in forum C Programming
    Replies: 8
    Last Post: 02-14-2003, 08:28 AM
  5. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21