Results 1 to 3 of 3

Thread: Ubuntu 12.10 vs 13.04 -- g++ compiler crazyness

  1. #1
    Join Date
    Oct 2009
    Beans
    90

    Ubuntu 12.10 vs 13.04 -- g++ compiler crazyness

    Every time I try a new Ubuntu release my programs stop compiling... Last time I found out they played around with some option and I had to change the order my libraries were listed. This time instead...

    First of all the code for the source file tryit.cpp:
    Code:
    #include <iostream>
    #include "library.hpp"
    
    int main ()
    {
        int size = Get_Terminal_Size ();
        std::cout << size << std::endl;
        return 0;
    }
    Then the library.hpp file:
    Code:
    #ifndef library_h_
    #define library_h_
    
    // Dependecies
    #include <sys/ioctl.h>        // ioctl ()
    #include <cstdlib>
    
    /*!
        This function determines the current size of the terminal being used.
    
        @return:            width of the terminal
    */
    inline int Get_Terminal_Size ()
    {
        // initalized to default value in case the macros are both not defined
        int cols = 80;
    //    int lines = 24;
    
    #ifdef TIOCGSIZE
        struct ttysize ts;
        ioctl (STDIN_FILENO, TIOCGSIZE, &ts);
        cols = ts.ts_cols;
    //    lines = ts.ts_lines;
    #elif defined (TIOCGWINSZ)
        struct winsize ts;
        ioctl (STDIN_FILENO, TIOCGWINSZ, &ts);
        cols = ts.ws_col;
    //    lines = ts.ws_row;
    #endif /* TIOCGSIZE */
    
        return cols;
    }
    
    #endif /* library_h_ */
    compile command: g++ -o test tryit.cpp

    Ubuntu 12.10 -----> COMPILES!
    Ubuntu 13.04 -----> I WISH!

    The compilers outputs the following:
    Code:
    In file included from tryit.cpp:2:0:
    library.hpp: In function ‘int Get_Terminal_Size()’:
    library.hpp:26:9: error: ‘STDIN_FILENO’ was not declared in this scope
    That macro he is crying about is included in unistd.h, which once upon a time I found to be, in some way, included in c++ via cstdlib, although cstdlib is just another way to call stdlib.h, which is a different header than unistd.h.
    Anyway, in 12.10 it works, in 13.04 I have to substitute cstdlib with unistd.h, otherwise it does not work.

    Can anybody explain to me WHY? /cry
    Last edited by Dirich; June 28th, 2013 at 09:22 PM.

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Ubuntu 12.10 vs 13.04 -- g++ compiler crazyness

    It's a gcc 4.7 thing, I think --> http://gcc.gnu.org/gcc-4.7/porting_to.html
    Many of the standard C++ library include files have been edited to no longer include <unistd.h> to remove namespace pollution.

  3. #3
    Join Date
    Oct 2009
    Beans
    90

    Re: Ubuntu 12.10 vs 13.04 -- g++ compiler crazyness

    That sounds like it, thanks!
    Poor ubuntu guys, I always blame tham...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •