g++

c++ initialization order of globals

Is this portable or at least safe to use with g++? #include <iostream> #include <vector> struct c {}; std::vector<c*> v; struct i : c { i () { v.push_back (this); } } a, b, c; int main () { std::cout << v.size () << "\n"; // outputs 3 with g++ } EDIT: Ok, what I need turned out to be a bit harder: The same code with templates: #...

g++ linking issues: undefined reference to functions

I used CMake and Visual C++ to build the HyDE library. Then, still in VC++, I was able to successfully create code and build an executable that links into HyDE.lib and the HyDE header files. I then discovered that in order to work with others at my company, it would be preferable to develop in Eclipse CDT. Knowing very little about Ec...

Why error is emitted two times?

Fully aware, that the question I am asking is outside the purview of the C++ Standard, I am curious to know why GCC throws the same error twice? I know why the error is there, but am looking forwards to understand why the duplication in error message. #include <iostream> using namespace std; struct A{ virtual void f1() = 0; }; stru...

Have I found a bug in Clang?

I tried to compile the code below with Clang class Prasoon{ static const int dummy = 0; }; int const Prasoon::dummy = 0; int main(){} The above code did not give any error when compiled with Clang. prasoon@prasoon-desktop ~ $ clang++ --version clang version 2.8 (trunk 107611) Target: i386-pc-linux-gnu Thread model: posix prasoo...

G++ 4.5 Bug: No diagnostic for narrowing in initializer list

I tried the following code: int main() { int x {23.22}; } which includes an initialization that requires narrowing, but the code compiles fine without any error or warning. On the other hand, the following code gives error: int main() { int x[]{23.22}; } Have I found a bug or what? PS: I'm currently using GCC 4.5.0 ...

eclipse cdt relative include path?

Hey all. I've downloaded and moved the Xerces (v3.1.1) source here: /usr/include/xerces and I can see the source in the project explorer like this: MyCppProject Binaries Includes [...] // some other directories xerces dom [...] // some other directories And, here's my simple C++ code: #include <xercesc/util/PlatformUtils...

linux g++ linking 64 bit shared library code to static libraries

Context: I can create a shared object library which is linked to a static library without any problems on 32bit linux. When I attempt the same build on 64bit linux, I see this linker error: relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC This error is quite common on...

How can a declaration conflict with itself?

This is the error I'm getting when trying to compile some code that uses taucs (not my code): .../taucs/src/taucs.h:554: error: conflicting declaration ‘typedef struct taucs_ccs_matrix taucs_ccs_matrix’ .../taucs/src/taucs.h:554: error: ‘taucs_ccs_matrix’ has a previous declaration as ‘typedef struct taucs_ccs_matrix taucs_ccs_matrix’ ...

how do i compile a C++program to work in the windows operating system using g++ for linux?

I am new to writing programs in c++ and i want to know if there is a way to export it to a windows format. Also what is a good way to learn objective-c, is it very different from c++? Thank you in advance. ...

vc++ .h file compile error in g++

Hi, I have a .h,.dll and a .lib file given to me by a vendor all compiled in visual studio. I try to link the library in g++ and I get an error in the .h file that I dont understand. The error is: error: qualifiers can only be specified for objects and functions at several lines that have no qualifiers. It occurs randomly at if statem...

Optmization flags with g++

I am using g++ to compile a C++ code; a scientific simulation software. Currently I am using the -O3 and -funroll-loops flags. I could notice a big difference between -O0, -O1, -O2, and -O3, and almost no difference with -funroll-loops. Would you have any suggestions to help me to increase the optimization or tricks that I can use to g...

Compile C++ code for AIX on Ubuntu?

Hi All, Question in one sentence: How can I compile code for AIX using G++ on Ubuntu? (Assuming it is possible) I hope that it is as simple as adding an option to the make file to specify target processor. I am a novice when it comes to most things compiler related. Thank you in advance. ...

g++ standards support

I am a bit puzzled reading this: Gcc 4.5 online manual --- Standards section. They explain this The original ISO C++ standard was published as the ISO standard (ISO/IEC 14882:1998) and amended by a Technical Corrigenda published in 2003 (ISO/IEC 14882:2003). These standards are referred to as C++98 and C++03, respectively. GCC imple...

Linking with specific library ( libstdc++.so.5 and libstdc++.so.6 )

Hi all, A simple question - is there any way to make the g++ linker to link with a specific libstdc++ library version? I didn't find anything useful in the man page of gcc/g++, neither in other questions here. Here's the situation - my application uses a specific shared library, that's built with libstdc++.so.5 and I want to install a...

what is the g++ option to build ia64 binaries

what is the g++ option to build ia64 binaries ...

C++ templated function and forward declarations

I'm working on some code that compiles and links (and even has released commercial products) on Windows using MSVC. It doesn't compile with GCC though, I get the following errors: .../CBaseValue.h: In member function 'bool CBaseValue::InstanceOf()': .../CBaseValue.h:90:18: error: invalid use of incomplete type 'struct CValueType' .../CB...

c++ : vector addition operation

Hi, I am trying to add two Vectors below is the code snippet :- #include <iostream> #include <vector> using namespace std; int main() { unsigned int i = 0; vector <float> v1; vector <float> v2; vector <float> v3; cout << "Filling the Numbers\n"; for (i=5;i < 125 ; i = i + 5) { ...

what are all these features of gcc? (-l -a -etc)

Can someone tell me in plan and simple terms what some of the more important features and options are for gcc and what they do? I look at the man pages and my head feels like exploding lol. ...

adapting an old-fashioned cast of a std::streampos to be g++ 4.4 compatible

Good afternoon, I'm attempting to get some old-fashioned code to function in g++ 4.4. My understanding is the code compiled fine in g++ 4.0, but g++ has become more strict between 4.0 and 4.4. This code in particular causes the compiler to stop and complain: sprintf(s,"%.7d",(long)tellp()); tellp() is a std::streampos object. The ab...

How to specify c++0x flag on cent os

The command g++ -o myprogram myprogram.c -std=c++0x works well on ubuntu but when I try the same with centos it throws me an error cc1plus: error: unrecognized command line option "-std=c++0x". Even google doesn't give the answer. Have anybody experienced it before? Does anybody know the solution? ...