g++

What does CC?= in a Makefile mean?

I have a Makefile for a C program that has the declaration CC?=gcc Changing it to CC?=g++ does NOT make it compile with g++. Changing it to CC=g++ DOES make it use g++. So I wonder what the ?= operator does? My guess is that it looks at a environment variable to decide which compiler to use and if it's not set then use gcc? Any...

Print layout of C++ object with g++ compiler

Is there a way to print the layout of a C++ object using the g++ compiler or any other means. A simplified example (assuming int takes 4 bytes) class A{ int a; }; class B:public A{ int b; } so the output would be A- 0 4 + a + B- 0 4 8 + A.a + b + It would be useful to understand the layout of objects (...

How do you use C++0x raw strings with GCC 4.5?

This page says that GCC 4.5 has C++ raw string literals: http://gcc.gnu.org/projects/cxx0x.html But when I try to use the syntax from this page: http://www2.research.att.com/~bs/C++0xFAQ.html#raw-strings #include <iostream> #include <string> using namespace std; int main() { string s = R"[\w\\\w]"; } I get this error: /opt/...

C++0x is assignment of braced-init-list to an array correct?

n3092 (final draft) says, under 5.17/9 A braced-init-list may appear on the right-hand side of - an assignment to a scalar [...] - an assignment defined by a user-defined assignment operator [..] While in GCC 4.5.1-pre9999, I can compile this (using -std=c++0x, NOT -std=gnu++0x) #include <iostream> int main() { ...

Invoking C++ code from Java (GCJ)

I'm trying to invoke C++ from Java using GCJ using the CNI, so far I'm able to invoke Java code from C++. How can I invoke C++ from Java using the CNI? ...

gcc workaround while using shared_ptr to insert in std::set

Hi, This code fails to compile using g++ 4.2.1 but works fine under vc++ v8. #include <set> typedef std::set<int *> IntPtrSet; IntPtrSet iptrSet; typedef std::set<shared_ptr<int>> IntPtrSet2; IntPtrSet2 iptrSet2; void AddIntegers(int& x) { iptrSet.insert(&x); iptrSet2.insert(&x); } shared_ptr is similar to boost::shared_ptr...

Why is gcov creating Code Coverage data for STL Headers?

When I run gcov foo.cpp it not only generates the code coverage report for foo.cpp, but for all the STL headers used by foo.cpp. Is there a way to prevent this? It seems to ignore standard library headers like <ctime>. Edit Just ran across this post on the gcc mailing list: Re: gcc, gcov and STL ...

Dynamic loaded libraries and shared global symbols

Since I observed some strange behavior of global variables in my dynamically loaded libraries, I wrote the following test. At first we need a statically linked library: The header test.hpp #ifndef __BASE_HPP #define __BASE_HPP #include <iostream> class test { private: int value; public: test(int value) : value(value) { std::...

how-to add "warnings as error" rule to Qt .pro file ?

Hi, When I usually work on a C++ project, one of the first things I do is setting up the "treat warning as errors" on my compiler. When using Qt, qmake generates the Makefile for you and doesn't include this option on the compilation commands. I'm pretty sure there is a way to add such an option (and others) into the generated Makefile...

g++ linker can't find const member function

I have a Point class (with integer members x and y) that has a member function withinBounds that is declared like so: bool withinBounds(const Point&, const Point&) const; and defined like this: bool Point::withinBounds(const Point& TL, const Point& BR) const { if(x < TL.getX()) return false; if(x > BR.getX()) return false; ...

Academic question: typename

Possible Duplicate: Why do I need to use typedef typename in g++ but not VS? Hi, recently I accounted with a "simple problem" of porting code from VC++ to gcc/intel. The code is compiles w/o error on VC++: #include <vector> using std::vector; template <class T> void test_vec( std::vector<T> &vec) { typedef std::ve...

mysql-connector-c++ - ‘get_driver_instance’ is not a member of ‘sql::mysql’

I am a beginner at c++ and figured the only way I am going to learn is to get dirty with some code. I am trying to build a program that connects to a mysql database. I am using g++, on linux. With no ide. I run "make" and this is my error: hello.cpp:38: error: ‘get_driver_instance’ is not a member of ‘sql::mysql’ make: *** [hello.o] Er...

Compilation error while compiling an existing code base

Hi, While building an existing code base on Mac OS using its native build setup I am getting some basic strange error while compilation phase. Does any of you have any idea, as I have seen it's been discussed earlier as well in this forum without any good reason. I can not see any conflicting files being included. But still I am unable...

Illegal Instruction When Programming C++ on Linux

Heyo, My program, which does exactly the same thing every time it runs (moves a point sprite into the distance) will randomly fail with the text on the terminal 'Illegal Instruction'. My googling has found people encountering this when writing assembly which makes sense because assembly throws those kinds of errors. But why would g...

Boost.Thread Linking - boost_thread vs. boost_thread-mt

It's not clear to me what linking options exist for the Boost.Thread 1.34.1 library. I'm on Ubuntu 8.04 and I've found that when using either boost_thread or boost_thread-mt during linking both compile and run, but I don't see any documentation on these or any other linking options in above link. What Boost.Thread linking options are a...

C++/g++: Concurrent programm

Hi, I got a C++ program (source) that is said to work in parallel. However, if I compile it (I am using Ubuntu 10.04 and g++ 4.4.3) with g++ and run it, one of my two CPU cores gets full load while the other is doing "nothing". So I spoke to the one who gave me the program. I was told that I had to set specific flags for g++ in order t...

C++ template function compiles in header but not implementation

I'm trying to learn templates and I've run into this confounding error. I'm declaring some functions in a header file and I want to make a separate implementation file where the functions will be defined. Here's the code that calls the header (dum.cpp): #include <iostream> #include <vector> #include <string> #include "dumper2.h" int ...

How to get POSIX strerror_r instead of GNU version?

How do I get the POSIX strerror_r instead of GNU version? I'm compiling with g++ on Ubuntu 8.04 with glibc version 2.7 ( based on what's in ). Edit On the above man page it says: Feature Test Macro Requirements for glibc (see feature_test_macros(7)): The XSI-compliant version of strerror_r() is provided if: (_POSIX_C_SOURC...

"Socket operation on non-socket" error due to strange syntax

I ran across the error Socket operation on non-socket in some of my networking code when calling connect and spent a lot of time trying to figure out what was causing it. I finally figured out that the following line of code was causing the problem: if ((sockfd = socket( ai->ai_family, ai->ai_socktype, ai->ai_protocol) < 0)) { See th...

Undefined reference to vtable

So, I'm getting the infamously horrible "undefined reference to 'vtable..." error for the following code (The class in question is CGameModule.) and I cannot for the life of me understand what the problem is. At first, I thought it was related to forgetting to give a virtual function a body, but as far as I understand, everything is all ...