Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:55:14+00:00 2026-05-30T19:55:14+00:00

How can I individually handle errors and warnings outputed by the GCC compiler? For

  • 0

How can I individually handle errors and warnings outputed by the GCC compiler?
For example, if a program is compiled,
how would I get all the errors to go to “error.txt”
and all of the warnings to go to “warnings.txt”
I assume there is an easy solution for this, but let me provide more detail:

I’ve written a GNU makefile to compile with GCC and the makefile rules are performed by bash.
I would like this branching decision to take place in the rule of my makefile.
So maybe something like this for example:

if (PROGRAM_HAS_NO_ERRORS_OR_WARNINGS); then\  
    echo "Everything went well";\  
else\  
    if (PROGRAM_HAS_WARNINGS); then\  
        echo "HERE ARE THE WARNINGS: " $(PROGRAM_WARNINGS);\  
    fi;\
    if (PROGRAM_HAS_ERRORS); then\  
        echo "HERE ARE THE ERRORS: " $(PROGRAM_ERRORS);\  
    fi;\
fi;

I was under the impression that the warnings were cout.. and errors were cerr..
and that cout corresponded to 1 and cerr corresponded to 2.
However, when I run something like this:

$(COMPILE) 1>warnings.txt 2>errors.txt  

everything goes to errors.txt

So I definitely don’t want to send it to a file and then parse through it if there is an easier way.


some other notes that may not be important:

if ($(COMPILE)); then\

/\ even if there are warnings, it will evaluate to true… UNLESS
I provide the flag “-Werror” which just makes the warnings errors and gcc refuses to compile the program

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:55:15+00:00Added an answer on May 30, 2026 at 7:55 pm

    This lends itself to a named pipe and a case statement similar to this:

    mkfifo errors.txt
    
    while read LINE; do
      case "$LINE" in
        *[Ee]rror*)error_function $LINE;;
        *[Ww]arning*)warning_function $LINE;;
        *)echo GENERAL ERROR MSG : $LINE;;
      esac
    done <errors.txt &
    
    make 2> errors.txt &
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The getRGB() method returns a single int. How can I get individually the red,
I am working on a RoR website and would like to handle server errors
Please one library per answer so that people can vote for the individually.
Is there a program or API I can code against to extract individual files
I want to alert the user whenever there's an AJAX error. You can do
How can I handle tilt left or tilt right mouse event in WPF? alt
I want to handle application wide error and show a ErrorView page in asp.net
I'm trying to get a handle on the amount of memory overhead associated with
Header files with declarations like this: void FooBar(System::Network::Win32::Sockets::Handle handle, System::Network::Win32::Sockets::Error& error /*, more fully-qualified
It's clear that you should be using exceptions to handle errors in your app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.