g++

Shared object symbol resolution

Hi, Suppose I have 2 static Libs S1 and S2 which are different versions of the same lib and have the same C (not C++) interface though implementations are different. 2 shared libs D1 and D2 each of which links to S1 or S2 only. Suppose an application A links with S2 which is the more recent of the static libs and dynamically loads bo...

Memory layout question

Do these two structs have the same memory layout? (C++) struct A { int x; char y; double z; }; struct B { A a; }; Further can I access x, y, z members if I manually cast an object of this to an A? struct C { A a; int b; }; Thanks in advance. EDIT: What if they were classes instead of structs? ...

Compilation error in Makefile, includes not showing up

I have a makefile as follows: CC = gcc CFLAGS = -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" $(INCLUDES) ifdef DEBUG CFLAGS += -g3 endif INCLUDES = \ -I../config.include \ -I../log.include \ -I../services.include SRC_DIR = src BIN_DIR = bin BINARY = report SRCS = $(shell ls $(SRC_DIR)/*.cpp) OBJS = $(SRCS:%.cpp=%....

Optimizing g++ when indexing an array with an injective function

I have a for loop where each step i, it processes an array element p[f(i)], where f(i) is an injective (one-to-one) map from 1...n to 1...m (m > n). So there is no data coupling in the loop and all compiler optimization techniques such as pipelining can be used. But how can I inform g++ of the injectivity of f(i)? Or do I even need to (c...

How can I control the way gcc/g++ automatically includes headers?

I've run into trouble in the past when I've tried porting some C++ code written on Mac OS X to a Linux system, or trying to compile code written against an older version of gcc/g++ with a newer one: It seems that some (older?) versions of gcc/g++ would automatically include some header files for you. For example, code that uses printf ...

Recycling variable name within single function

I have a function that contains two for loops, and I'm using a variable called count as the counter. I've chosen to recycle the name as the the first loop will finish it's execution completely before the second one begins, so there is no chance of the counters interfering with each other. The G++ compiler has taken exception to this via...

-D option is expanded incorrectly from g++ command line

In C++ CodeBlocks project I added the following definitions to the project settings, compiler settings, #define: _DEBUG DATA_DIR=\"/media/Shared/SiX/Data\" This produces the following g++ command line: g++ -Wall -g -fPIC -save-temps -D_DEBUG -DDATA_DIR=\"/media/Shared/SiX/Data\" -I../Includes -c /media/Shared/SiX/SiXConfigurat...

linking with a pragma with g++

In Visual C++, one may link to a library in the code itself by doing #pragma comment (lib, "libname.lib"). Is something similar possible in g++? ...

mutually referential classes yield "incomplete type" error

I have a situation in which A has a reference to a class C defined inside B, and C has an instance of class B. When I try to compile the code below, I get "field a has incomplete type". I assume this is because the compiler does not know how much memory it should allocate for an instance of A. class A; class B { public: class C { ...

Why do I get missing symbols for an explicit template specialization in a static library?

If I compile the following code: // // g++ static.cpp -o static.o // ar rcs libstatic.a static.o // #include <iostream> template < typename T > struct TemplatedClass { void Test( T value ) { std::cout << "Foobar was: " << value << std::endl; } }; template struct TemplatedClass < long >; I get a static library and if I run ...

calling C/C++ functions of a library compiled with g++, wthin a program compiled with gcc

Dear all, I have a set of software library modules which are developed in c++. So, I use g++ to compile my software. This has to be used by various existing applications which are written in C and compiled with gcc. When the other teams used g++ to compile their code, they started getting lot of compiler errors due to strict type che...

Initialization of member: bug in GCC or my thinking?

I've got an enum type defined in the private section of my class. I have a member of this type defined as well. When I try to initialize this member in the constructor body, I get memory corruption problems at run-time. When I initialize it through an initialization list in the same constructor instead, I do not get memory corruption pro...

Use static_assert to check types passed to macro

I unfortunately have several macros left over from the original version of my library that employed some pretty crazy C. In particular, I have a series of macros that expect certain types to be passed to them. Is it possible to do something along the lines of: static_assert(decltype(retval) == bool); And how? Are there any clever alte...

Failed to create a custom TCL interpreter with TclPro1.4: undefined reference to `__ctype_b'

I am trying to create a custom TCL interpreter with TclPro according instructions at TclPro User's Guide Chapter 7, but it fails with linking error undefined reference to __ctype_b. I have downloaded and installed TclPro 1.4 at /opt/ajuba/TclPro1.4/, and here is the custom interpreter I want to build: // file simple.cpp #include <proWr...

C++ - Operating on a string before runtime.

I have a string: B<T>::B() [with T = int] Is there any way I can get B<T> [with T = int] from this before run time somehow? :) EDIT: Simplifying: Is there any way to get X & Y separately from a static string XY defined as a preprocessor macro in any form before runtime? ...

Can I squeez my own program between the preprocessor and compiler?

Is this a stupid question? Or can I specify g++ to use a program between the preprocessor and compiler? Alternatively, I know that I can just run the preprocessor on a file (hence all the files). Then I am guessing there is a switch to run only the compiler. So I can manually invoke these two and put my program between. If so, how do I ...

g++ linking problem.

I'm having a weird linking problem and am only beginning programming with c++ so I'm not terribly sure what it means... main.cpp #include <iostream> main(void) { return 0; } Compiling esr@athena:~/programming/cpp$ g++ main.cpp esr@athena:~/programming/cpp$ ./a.out esr@athena:~/programming/cpp$ g++ main.cpp -L/home/esr/ogre/lib ...

Strange error, set<int>::begin() always returning const iterator

Why is set.begin() always returning a const iterator and not a standard one? 35 int test(){ 36 std::set<int> myset; 37 myset.insert(2); 38 myset.insert(3); 39 int &res = *myset.begin(); 40 return res; 41 } test.cpp:39: error: invalid initialization of reference of type ‘int&’ from expression of type ‘const int’ ...

what is g++-mp-4.3?

MacPorts installs something called g++-mp-4.3? Does the "mp" mean MacPorts, or is it something else? I can't find any documentation anywhere... Thanks! ...