Compiling C++11 with g++

Flags (or compiler options) are nothing but ordinary command line arguments passed to the compiler executable. Assuming you are invoking g++ from the command line (terminal): $ g++ -std=c++11 your_file.cpp -o your_program or $ g++ -std=c++0x your_file.cpp -o your_program if the above doesn’t work.

How to detect whether there is a specific member variable in class?

Here is a solution simpler than Johannes Schaub – litb‘s one. It requires C++11. #include <type_traits> template <typename T, typename = int> struct HasX : std::false_type { }; template <typename T> struct HasX <T, decltype((void) T::x, 0)> : std::true_type { }; Update: A quick example and the explanation on how this works. For these types: … Read more

usr/bin/ld: cannot find -l

To figure out what the linker is looking for, run it in verbose mode. For example, I encountered this issue while trying to compile MySQL with ZLIB support. I was receiving an error like this during compilation: /usr/bin/ld: cannot find -lzlib I did some Googl’ing and kept coming across different issues of the same kind … Read more

What is the difference between g++ and gcc?

gcc and g++ are compiler-drivers of the GNU Compiler Collection (which was once upon a time just the GNU C Compiler). Even though they automatically determine which backends (cc1 cc1plus …) to call depending on the file-type, unless overridden with -x language, they have some differences. The probably most important difference in their defaults is … Read more

Undefined reference to vtable

The GCC FAQ has an entry on it: The solution is to ensure that all virtual methods that are not pure are defined. Note that a destructor must be defined even if it is declared pure-virtual [class.dtor]/7. Therefore, you need to provide a definition for the virtual destructor: virtual ~CDasherModule() { }