g++ (MinGW), C++11 and SSE - c++

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!

Related

g++ does not recognize -stdlib=libstdc++

So I just reinstall gcc using home brew, when I compile a programme and try to use libstdc++... I get a error:
dhcp-18-189-47-44:openmp_code myname$ g++-4.8 -fopenmp tmp2.cpp -stdlib=libstdc++
g++-4.8: error: unrecognized command line option '-stdlib=libstdc++'
Someone has idea what is happening ? Thank you.
As the error message clearly says, g++ does not support -stdlib as an option. You can simply remove that option from the command line.
g++-4.8 -fopenmp tmp2.cpp
should be all you need.

c++/g++ --- Compilation Error.. fatal error: iostream: No such file or directory compilation terminated

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++

g++ doesn't output any errors

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!

What is the right way to add <random> header file?

I am trying to generate 64-bit random numbers with the use of mersenne_twister_engine but when I try to include #include <random>, the compiler gives me a warning shown below
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options. make: * [fuse.o] Error 1
How can I fix this?
... and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
Did you not read that bit? You need to add one of those to your compiler command line (or, if you're using an IDE, whatever method your IDE uses to set the options). Details on C++11 support in gcc can be found here.
For example (command line compiling), if your current command is
g++ -o myprog myprog.cpp
you would change it to something like
g++ -std=c++0x -o myprog myprog.cpp
random is introduced in C++11 so add this to your g++ option:
--std=c++0x
or
--std=gnu++0x
The option is probably in your makefile.

gnu gcc How to suppress warning: ‘typedef’ was ignored in this declaration [enabled by default]

I am using GNU gcc 4.6.2 on Fedora 16. I am writing an application using a 3rd party API, after compilation, I got a lot warnings.
warning: ‘typedef’ was ignored in this declaration [enabled by default]
Just wondering how can I suppress this? I compile my program with -Wall flag.
In this doc, http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html, it mentioned something like -Wunused-local-typedefs.
I have tried -Wno-unused-local-typedefs, but doesn't work.
Thanks.
-Wno-unused-local-typedefs works in GCC 4.8.
gcc allows you to specify that certain library include paths should be treated as system libraries with the -isystem switch which allows those headers special treatment with respect to the flags you use on the rest of your code. So for example if you have unused local typedefs from using certain Boost libraries in test.cpp (I ran into this using including the Boost signals2 library recently)
g++ -o test{,.cpp} -Wall -Wextra -Werror -I /usr/local/boost-1.55.0/include -L /usr/local/boost-1.55.0/lib
and the above does not build cleanly try the following
g++ -o test{,.cpp} -Wall -Wextra -Werror -isystem /usr/local/boost-1.55.0/include -L /usr/local/boost-1.55.0/lib
which will (provided the warnings coming from the Boost libraries you are including in test.cpp are your only problem of course).
According to the gcc-source-code(gcc/cp/decl.c:4108):
warning (0, "%<typedef%> was ignored in this declaration");
There is no command line flag(that is what the 0 stands for) to suppress this warning in gcc 4.6.2.
As -Wunused-local-typedefs is part of -Wall, make sure you don't have -Wall after -Wno-unused-local-typedefs. If you do, -Wall just turns the option back on again.
In C++17, you should use [[maybe_unused]].
For an overview of all attributes, please see http://en.cppreference.com/w/cpp/language/attributes.
Proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0212r0.pdf
(sorry, I could't post an example, as it's considered as badly indented by stackoverflow)
This GCC warning means that your typedef maybe duplicated and you should remove typedef keyword instead. For example:
typedef enum class Something {
THING1,
THING2,
} Something;
This code above is type duplicate, because enum class is defined as type already. So you must remove typedef keyword as well as Something at the end too!