g++

Increasing Optimization Level g++

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 17:22:37
问题 I'm trying to compile a relatively simple c++ program using cygwin and g++. I can compile it using the following command: g++ -o main main.cpp -lgmpxx -lgmp (note: the last two reflect the inclusion of the gmp libraries). I'd like to increase the level of optimization that this is compiled with. I thought that I could just change this command line to: g++ -o3 main main.cpp -lgmpxx -lgmp but this totally blows up. I get about two full screens of error messages. How can I increase the

Eclipse does not include C++ libraries correctly in Kubuntu

假装没事ソ 提交于 2019-12-12 16:28:52
问题 I'm having a problem with C++11 libraries. I'm using Eclipse in Kubuntu with latest gcc and g++ compilers. I'm using C++ 4.7.2 library. Eclipse finds all the libraries just fine, but still there are problems. For example: #include <random> typedef std::mt19937 myRandom; This code results an error: "Type 'std::mt19937' could not be resolved". It seems that not all functionality in random was not included. Same problem exists for cout and cin in iostream. What could be wrong? -Juho L 来源: https:

How to set GCC_COLORS in gcc4.9 to emit colorizing diagnostics messages?

情到浓时终转凉″ 提交于 2019-12-12 16:14:49
问题 gcc4.9 supports the colorizing diagnostics for compiler warning/error messages. We can enable it for a particular program using the option " fdiagnostics-color ". Currently I am using gcc4.9.1 and I append this particular option in my makefile as follows: CC = /home/mantosh/gcc-4.9.1/bin/g++ -std=c++1y -Wall -pthread DFLAG = -g -gdwarf-2 -fdiagnostics-color=always OUTFILE = test $(OUTFILE): test.cpp $(CC) $(DFLAG) -o $(OUTFILE) test.cpp clean: rm -f *.o $(OUTFILE) If I compile a *.cpp file a

explicit template parameter specification for ostream& operator<< puzzling compile error

Deadly 提交于 2019-12-12 15:30:15
问题 I have the following code: #include <iostream> //#include <algorithm> // compile error when `g++ -std=c++11`, fine otherwise using namespace std; template<typename T> class Foo { T x_; public: Foo(const T& x={}): x_(x){}; // default ctor, bounded rvalue default-initialized template<typename S> friend ostream& operator<<(ostream& lhs, const Foo<S>& rhs) { return lhs << rhs.x_; } }; int main() { Foo<double> foo(10.1); cout << foo << endl; operator<<(cout, foo) << endl; //puzzling compile-time

Why GCC allows catch by rvalue reference?

折月煮酒 提交于 2019-12-12 13:51:10
问题 The standard states that catching by rvalue reference should be illegal: Catch By Rvalue Reference, but I have the follwing code: #include <string> #include <iostream> using namespace std; int main(){ try { throw string("test"); } catch (string && s) { cout << s << endl; } return 0; } It successfully compiles without any warning with -Wall option. How does this happen? I am using gcc version 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC) 回答1: gcc 4.8.1 was the first C++11 feature complete version of

g++ Linking Error on Mac while compiling FFMPEG

跟風遠走 提交于 2019-12-12 13:24:09
问题 g++ on Snow Leopard is throwing linking errors on the following piece of code test.cpp #include <iostream> using namespace std; #include <libavcodec/avcodec.h> // required headers #include <libavformat/avformat.h> int main(int argc, char**argv) { av_register_all(); // offending library call return 0; } When I try to compile this using the following command g++ test.cpp -I/usr/local/include -L/usr/local/lib \ -lavcodec -lavformat -lavutil -lz -lm -o test I get the error Undefined symbols: "av

How to query for all base classes of a class at compile time?

谁说胖子不能爱 提交于 2019-12-12 13:08:08
问题 With std::is_base_of<A,B>::value one can check if a class A is a base class of class B . Is it also possible to query the compiler for all base classes of a class B , e.g., something like base_classes_of<B> returning a std::tuple containing all base classes of B ? Is there evtl. a non-standard extension in g++ that can accomplish this ? If this is not possible at all, does anyone know why? It sounds like a rather fundamental piece of information the compiler easily should have available?

Specialize function if argument has member variable

烈酒焚心 提交于 2019-12-12 12:32:46
问题 I have a function for error reporting that is templated because it can report errors for many different message classes: template <typename MSG> void reportErr(const MSG& msg) { std::cout << "ERROR: " << msg.error << std::endl; } However, some types of message have more detailed error that can be reported or other specialized error reporting, e.g. template<> void reportErr(const SpecificMsg& msg) { std::cout << "ERROR: " << msg.error; std::cout << ", details: " << msg.details << std::endl; }

Templates, inner structs, local types, and pure virtual functions, oh my

被刻印的时光 ゝ 提交于 2019-12-12 12:30:54
问题 Consider an example where a method is pure virtual, takes a parameter of a templated type (injected from an outer type), and that templated type is a local type (defined in a function body). This scenario causes a compile-time error under g++. Admittedly, this is quite a corner case, but it does originate from real code. Here's a compilable, reproducible example: #include <cstdio> template<typename T> struct Outer { struct InnerBase { virtual void foo(T const&) = 0; virtual void bar(T const&)

Initializing std::array with Static Storage Duration with a Parameter Pack Expansion and an Additional Value

我是研究僧i 提交于 2019-12-12 12:23:38
问题 While asking another question recently, I stumbled upon some strange behavior of GCC when initializing a std::array with a parameter pack expansion followed by another element . I have already discussed this briefly with Jarod42 in the comments there but I believe it should better be asked as a new question. For example, consider the following code that is supposed to provide a utility make_array function that takes an arbitrary number of parameters and std::forward s them to the std::array