Whenever I try to compile a c++ code with g++ on terminal, I can't seem to get g++ to output any error messages even though I am certain that there are errors that should be caught during compile time (such as syntax, reference types...).
I tried several ways such as this make file:
all:
g++ -W -Wall -Werror main.cpp
All it does is output:
make: *** [all] Error 1
which isn't that useful, obviously...
Typing things like this:
g++ -W -Wall -Werror main.cpp
directly to terminal (without the make file) doesn't output any messages at all.
However this successfully outputs all of the errors while compiling:
cc main.cpp
My question is: how do I make g++ to output error messages so I can know where to correct my code?
Just guessing - is it possible your terminal doesn't print stderr? Say, for example, it moves it to a log file or something?
Try running
g++ [whatever your arguments are] |& cat
(this is if you use tcsh)
or
g++ [whatever] 2>&1 | cat
if you use bash.
Try something simple like this:
g++ -c main.cpp
Make reports an error when one of it's tasks returns non-0 status. If g++ silently returns non-0 - well, i suppose it's broken somehow. Check $? after you've run g++. Also, try g++ --version - will it report anything at all? Also you could run it under debugger, just to be sure.
Try adding a line like
#warning hello from here
(or perhaps #error instead of #warning) into main.cc near the beginning (perhaps as the first line).
If
gcc -Wall -v main.cc
don't give any output (notably no warnings or errors) that means that your gcc is broken. Perhaps type /usr/bin/gcc instead of just gcc
BTW, Apple don't like GCC (because they dont like its GPLv3+ license). Maybe it is worth your time to build [using e.g. ..../configure --program-suffix=-local] and install a newer GCC (perhaps from the released source tar ball of the compiler). Current version is 4.8.1!
Related
I use Ubuntu 14 and try to compile a c++ program in the terminal. Until now I used g++ and compiling worked without problems. As I prefer the error messages from clang I want to work with clang++ from now on.
So far I used the command
g++ -oexec main.cpp file.cpp
but when I try
clang++ -oexec main.cpp file.cpp
I get the error
clang: error: cannot specify -o when generating multiple output files
It works for me. I think you are also passing '-c' flag to the compiler while compiling with clang.
When you pass '-c', it will not work either with clang/gcc. This is because when you pass '-c' you are essentially saying that compile each file into object file (.o files), hence, providing '-o' in that case is incorrect.
This is a list of all Clang flags. As you can see "oexec" is not one of them. Instead Clang is reading your command as -o (Write output to ) and spits out the error, because you can't use -o when outputting to multiple files.
I've written a program, saved it on the desktop under the name 'Swap.cpp' and when I run gdb (the first time), I get the error:
"/Users/myname/Desktop/Swap": not in executable format: File format
not recognized.
I have no idea what I'm doing wrong. Any help will be appreciated.
Sorry I should've given more information:
I am using Mac OS.
I've already compiled the program and have the Swap.o file that I can see on my desktop.And here are the commands that I enter while trying to run the debugger from bash:
$ clang++ -g Swap.cpp -o Swap
$ ./Swap
this runs Swap and then I try to access the debugger using:
$ gdb Swap
that then gives me the aforesaid message. I tried doing what Rakholiya Jenish suggested but to no avail.
To run gdb on windows:
path_to_gdb.exe program_to_debug
If the compilation was not proper, either compile it with your IDE (if you are using) or with g++ using cmd.exe as:
g++ -g Swap.cpp -o output -lm
I figured out how to use lldb instead of gdb. lldb works just fine. Here is what I did:
$ clang++ -g -o Swap Swap.cpp
$ lldb Swap
Thank you all for your help.
i'm like working client-server application..
I'm trying to run the server - CountryServer.c file..
i tried with g++ and gcc and i got compilation errors.. i even googled and got answers.. sadly i still got the same errors..
with gcc
oh, i even also tried to enable std=c++11
and std=c++0x but it says no input files.. >.<
i enabled using this command:
gcc -std=c++11
and also tried this other enabled commands:
g++ -std=c++1 CountryServer.c -o CountryServer
and
g++ -Wall -g -std=c++11 CountryServer.c -o CountryServer
for both 0x & 11
andd,i've also checked which version has the iostream and also checked the gcc or g++ version >.<
i really dont understand and dont know what other ways/solutions/methods..
please help me! thanks ! :D
for iostream error,
can you please try compiling with g++
or
compiling gcc with option -lstdc++
gcc -o -lstdc++
i was compiling a lex.yy.cc and it is giving me the following error: FlexLexer.h no such file or directory
I have tried to put this .h on the same file as the code persé, and it stills gives me the error, i tried all the following ways to compile it and the web is not giving me a clear answer to my problem:
g++ lex.yy.cc
g++ lex.yy.cc -lfl
g++ lex.yy.cc -lm
g++ lex.yy.cc -lfl -lm
gcc lex.yy.cc -lm
gcc lex.yy.cc
nothing happend, i really dont know what else to try, i have changed the enviroments variables a 100 times and doesnt work. Please help :)
As #user2912836 stated try the -I command, I've run into the same problem before and its worked for me.
More info on directory searching: https://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#SEC1s
By "nothing happened", did you mean it was giving you the same error, or it just didn't output anything?
If it's the first case, I suggest you use the -I option to tell gcc where your headers file are.
If it's the second case, it probably compiled. See if there is an a.out file in your directory.
When I try to compile the next simple example of code:
echo "#include <cmath>" | g++ -x c++ -c - -m64 -mfpmath=both -std=gnu++11 -o /dev/null
(along with -m64 option is activated (by default) a using of SSE (say, AVX)).
It is appear the following error message:
In file included from <stdin>:1:0:
c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/cmath:1040:11: error: '::double_t' has not been declared
c:\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/cmath:1041:11: error: '::float_t' has not been declared
Is this a bug?
Without -mfpmath=both option an error does not happen.
My workaround is to add the -D__FLT_EVAL_METHOD__=2 (and -Wp,-w if -Werror is present, because of "is redefined" warning) to g++'s option list. I think that this is a dirty way.
This error is in wrong commit on mingw-w64 trunk. I wrote a bug report for this. Thanks!