CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2009
    Location
    Boston
    Posts
    364

    std::cout and gfortran print*, don't output to the screen

    I am not sure where to post this other than here.

    I am trying to figure out why an app gives different output when compiled under Ubuntu 10.10 and CentOS 5.5. I am pretty sure that the issue is that the Cent version has gcc 4.1 installed, while Ubuntu has gcc 4.4. I am trying to print from some fortran code using print*, as I have always done, but nothing appears on the terminal. I don't know how to debug this if I can't print any intermediary output.

    I also tried std::cout << from inside the cpp code, but that doesn't do anything either. There aren't any compiler errors or warnings, so what did I miss?

    Any suggestions???

    I am wondering if there is a difference in the header files between 4.1 and 4.4 and if I don't now have something I need. I would expect a compiler error if that was the case.

    LMHmedchem

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std::cout and gfortran print*, don't output to the screen

    Quote Originally Posted by LMHmedchem View Post
    I also tried std::cout << from inside the cpp code, but that doesn't do anything either. There aren't any compiler errors or warnings, so what did I miss?
    Just because a C++ compiles doesn't mean it will run correctly. All the compiler does is ensure that the program is syntactically correct. Whether it logically correct is another story.

    Secondly, cout can be anything the runtime says it is -- most of the time, it is the console, but doesn't have to be. For example, if you wirte a GUI Windows program, when you issue a "cout", you don't see any output.

    I do not know enough as to the type of application you're developing, but if the concept of a console window doesn't exist, or the cout has been redirected to another output stream, then that's the reason why you don't see anything.
    Code:
    I am wondering if there is a difference in the header files between 4.1 and 4.4 and if I don't now have something I need. I would expect a compiler error if that was the case.
    Different header files do not necessarily mean you will get a compiler error. All it guarantees is that your program may not run correctly if the compile/link is successful.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    May 2009
    Location
    Boston
    Posts
    364

    Re: std::cout and gfortran print*, don't output to the screen

    Thanks again for the advice Paul.

    The odd thing is that the app runs and gives the correct output for both windows and linux. It just doesn't print to the terminal in linux, where it does in cygwin bash. The two code bases are obviously not identical, since there are different functions for fork/create_process and the pipes.

    I originally had a difference in output between the two versions, and I was trying to debug that with some print statements. I solved the difference in output by compiling the linux under gcc3.4 instead of 4.1. Now it works, but it still can't print.

    This app is a parent in cpp that forks a child process (also in cpp). The child has a large fortran function, which calls some cpp along the way. I can only guess that the issue is in the way the the child is launched, or in the pipes, since the child main and parent main are src files that are different between the windows and linux versions. I am trying to print from the fortran function, or from the cpp that is called by the fortran (both part of the child process). This is a command line app.

    What should I look for in the code that would indicate that cout is being redirected to somewhere other than the terminal?

    LMHmedchem

  4. #4
    Join Date
    Mar 2011
    Posts
    16

    Re: std::cout and gfortran print*, don't output to the screen

    the stdout is usually the console...it happened to me too..but in my case the o/p buffer wasnt being flushed (even on using flush() )...std::cin causes the o/p buffer to be flushed...so try to have this after your std::cout and see if it was this precluding the display

  5. #5
    Join Date
    May 2009
    Location
    Boston
    Posts
    364

    Re: std::cout and gfortran print*, don't output to the screen

    Quote Originally Posted by ustulation View Post
    the stdout is usually the console...it happened to me too..but in my case the o/p buffer wasnt being flushed (even on using flush() )...std::cin causes the o/p buffer to be flushed...so try to have this after your std::cout and see if it was this precluding the display
    So add some std:cin statements after the cout to see if that helps?

    LMHmedchem

  6. #6
    Join Date
    Mar 2011
    Posts
    16

    Re: std::cout and gfortran print*, don't output to the screen

    do it for the first one...it'll help exhaust trivial possibilities maybe

  7. #7
    Join Date
    May 2009
    Location
    Boston
    Posts
    364

    Re: std::cout and gfortran print*, don't output to the screen

    I got this solved thanks to help from Corona688 at the unix and linux/programming forum.

    As Paul McKenzie suggested, cout and cerr were indeed being re-directed elsewhere.
    Code:
    #ifdef RELEASEVERSION
       freopen( "/dev/null", "w", stdout);
       freopen( "/dev/null", "w", stderr);
    #endif
    I didn't know that RELEASEVERSION had been defined here, so I wasn't checking the compiler directives very carefully. Commenting out the above corrects the issue. The above is a sensible code addition, since if there is an error, the child is supposed to report that back to the parent as an error code, not send it to a terminal, which may or may not exist in certain cases.

    Thanks for all the help. This can be marked as solved, or am I supposed to do that myself?

    LMHmedchem

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured