G ++ does not display any errors

Whenever I try to compile C ++ code with g ++ on a terminal, I cannot get g ++ to output any error messages, although I am sure there are errors that should be detected at compile time (for example, syntax, reference types ...).

I tried several ways like make make:

all: g++ -W -Wall -Werror main.cpp 

Everything he does is output:

 make: *** [all] Error 1 

which is not so useful, obviously ...

Entering such things:

 g++ -W -Wall -Werror main.cpp 

directly to the terminal (without the make file) does not display any messages at all.

However, this successfully displays all the compilation errors:

 cc main.cpp 

My question is: how do I get g ++ to display error messages so that I can know where to fix my code?

+4
source share
4 answers

Just guessing - is it possible that your terminal is not printing stderr ? Say, for example, does it move it to a log file or something else?

Try to run

 g++ [whatever your arguments are] |& cat 

(this is if you use tcsh) or

 g++ [whatever] 2>&1 | cat 

if you use bash.

+2
source

Try something simple:

 g++ -c main.cpp 
0
source

Make an error message when one of the tasks returns a non-0 status. If g ++ silently returns non-0 - well, I guess it somehow broke. Check $? after running g ++. Also, try g ++ --version - will it not report anything at all? You can also run it under the debugger to be sure.

0
source

Try adding a line like

 #warning hello from here 

(or perhaps #error instead of #warning ) in main.cc at the beginning (possibly on the first line).

If a

 gcc -Wall -v main.cc 

give no output (especially no warnings or errors), which means your gcc broken. Maybe type /usr/bin/gcc instead of gcc

By the way, Apple doesn't like GCC (because they don't like its GPLv3 + license). Maybe you should spend your time creating [using, for example, ..../configure --program-suffix=-local ] and install a new GCC (possibly from the released source of the tar ball compiler). The current version is 4.8.1!

0
source

All Articles