g++

Visibility of template specialization of C++ function

Suppose I have fileA.h which declares a class classA with template function SomeFunc<T>(). This function is implemented directly in the header file (as is usual for template functions). Now I add a specialized implementation of SomeFunc() (like for SomeFunc<int>()) in fileA.C (ie. not in the header file). If I now call SomeFunc<int>() f...

What is the VTable Layout and VTable Pointer Location in C++ Objects in GCC 3.x and 4.x?

I am looking for details of the VTable structure, order and contents, and the location of the vtable pointers within objects. Ideally, this will cover single inheritance, multiple inheritance, and virtual inheritance. References to external documentation would also be appreciated Documentation of GCC 4.0x class layout is here and the...

Problem Linking "static" Methods in C++

I want to call a few "static" methods of a CPP class defined in a different file but I'm having linking problems. I created a test-case that recreates my problem and the code for it is below. (I'm completely new to C++, I come from a Java background and I'm a little familiar with C.) // CppClass.cpp #include <iostream> #include <pthrea...

Performance improvements moving from g++/gcc 3.2.3 to 4.2.4.

We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance improvements on some of our code base is significant. I've tried searching the gcc buzilla database to find hints as to what bugs may have had such a dramatic improvement but I didn't find any individual bug that stood out as being a candidate. Are the i...

What are some recommendations for porting C++ code to the MacOS?

For a upcoming project, there are plans to port the existing C++ code that compiles on Windows and Linux to the MacOS(leopard). The software is command line application, but a GUI front end might be planned. The MacOS uses the g++ compiler. By having the same compiler as Linux, it does not seem like there would be any issues, but there...

What is the difference between g++ and gcc?

What is the difference between g++ and gcc? Which ones should be used for general c++ development? ...

Accessing protected members from subclasses: gcc vs msvc

In visual C++, I can do things like this: template <class T> class A{ protected: T i; }; template <class T> class B : public A<T>{ T geti() {return i;} }; If I try to compile this in g++, I get an error. I have to do this: template <class T> class B : public A<T>{ T geti() {return A<T>::i;} }; Am I not supposed to do ...

Qt Application fails spectacularly

I'm trying to link a Qt application with its libraries and the linker (MinGW) spews hundreds of lines like the following, and I am unsure how to proceed. cpp: undefined reference to `_Unwind_SjLj_Register' c:/qt/lib/libQtCore.a(qcoreapplication_win.o)(.text+0x29d):qcoreapplication_win. cpp: undefined reference to `_Unwind_SjLj_Unreg...

Undefined Symbol ___gxx_personality_v0 on link

I've been getting this undefined symbol building with this command line: $ gcc test.cpp Undefined symbols: "___gxx_personality_v0", referenced from: etc... test.cpp is simple and should build fine. What is the deal? ...

GCC and ld can't find exported symbols...but they're there!

I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form: app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetStatusStr(int)' Classes in the library see...

C++ two or more data types in declaration

...

Simple C++ code not working

This very simple code gives me tons of errors: #include <iostream> #include <string> int main() { std::string test = " "; std::cout << test; } I tried to compile it on linux by typing gcc -o simpletest simpletest.cpp on the console. I can't see why it isn't working. What is happening? ...

g++ partial linking instead of archives?

I'm pretty new to the C++ build flow, and I'm thinking of switching to use partial linking for my libraries instead of creating ar archives. I'm hoping to reduce link time in an inevitable final compilation step that I have, and I figure partial linking some libraries once could save me time over linking everything in that final step. I...

C++: undefined reference to static class member

Hey, Can anyone explain why following code won't compile? At least on g++ 4.2.4. And more interesting, why it will compile when I cast MEMBER to int? #include <vector> class Foo { public: static const int MEMBER = 1; }; int main(){ vector<int> v; v.push_back( Foo::MEMBER ); // undefined reference to `Foo::M...

return 0 implicit

The last week on the ACM ICPC Mexico competition, I missed a "return 0" on a C++ program. For this reason we got punished with 20 minutes. I had read that the standard does not oblige us to write it at the end of a main function. It is implicit, isn't it? How can I prove it? We were using a Fedora system with a G++ compiler. ...

What happens if you don't return a value in C++?

Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin >> input.x; cin >> input.y; } Of course forgetting to actually return the struct I just created. Oddly enough, the values in the struct that was returned by this function got initialized to zero (when compiled using g++ t...

g++ undefined reference to typeinfo

I just ran across the following error (and found the solution online, but it's not present in Stack Overflow): (.gnu.linkonce.[stuff]): undefined reference to [method] [object file]:(.gnu.linkonce.[stuff]): undefined reference to `typeinfo for [classname]' Why might one get one of these "undefined reference to typeinfo" lin...

Can I make GCC warn on passing too-wide types to functions?

Following is some obviously-defective code for which I think the compiler should emit a diagnostic. But neither gcc nor g++ does, even with all the warnings options I could think of: -pedantic -Wall -Wextra #include <stdio.h> short f(short x) { return x; } int main() { long x = 0x10000007; /* bigger than short */ printf...

Question about g++ generated code

Dear g++ hackers, I have the following question. When some data of an object is overwritten by a faulty program, why does the program eventually fail on destruction of that object with a double free error? How does it know if the data is corrupted or not? And why does it cause double free? ...

Can you really have a function/method without a body but just a try/catch block?

Note that this function does not have a "{" and "}" body. Just a try/catch block: void func( void ) try { ... } catch(...) { ... } Is this intentionally part of C++, or is this a g++ extension? Is there any purpose to this other than bypass 1 level of {}? I'd never heard of this until I ran into http://stupefydeveloper.blog...