g++

How to initialize all elements in an array to the same number in C++

I'm trying to initialize an int array with everything set at -1. I tried the following, but it doesn't work. It only sets the first value at -1. int directory[100] = {-1}; Why doesn't it work right? ...

C++ error: ‘string’ has not been declared

In my header file I'm getting the error: ‘string’ has not been declared error but at the top of the file I have #include <string>, so how can I be getting this error? ...

Compile Problem with MySQL C API on MAC OS X 10.6

Hi guys, i've a Problem with MySQL C API and Mac OS X 10.6. When i want to compile a SQL Client Program, it aborts with this Error Message ld: library not found for -lmysqlclient collect2: ld returned 1 exit status I compile with this command: g++ -I /usr/local/mysql/include/ -L /usr/local/mysql/lib/ -lmysqlclient main.cp...

How to assign a string value to a string variable in C++

Shouldn't this work? string s; s = "some string"; ...

Ctypes "symbol not found" for dynamic library in OSX

Hello. I have made a C++ library and have built a .dylib dynamic library from it. However when I load it with ctypes, it fails. Something doesn't seem to have linked properly. I have no idea why. The error (The relevant part): cscalelib.setup_framebuffer(flip,surface.frame_buffer,surface.texture,surface._scale[0],surface._scale[1])...

How to make a copy of a char and not a reference in C++

If I declare a function like this: string hash (char* key) then any change I make to key will also change it's value when the function exits, correct? I want to make a copy of it in the function so that I can safely change it without changing the original value. I tried this, but it doesn't work. char temp = key; How can it be do...

How to track down a double free or corruption error in C++ with gdb

When I run my C++ program it crashes with this error. * glibc detected ./load: double free or corruption (!prev): 0x0000000000c6ed50 ** I'm trying to track it down using cout statement but am finding it difficult. Could gdb make this easier? How is it done? ...

oprofile unable to produce call graph

hello I am trying to use oprofile to generate call graph. Compiler is g++, platform is linux x86-64, linker is gfortran C++ code is compiled with -fno- omit-frame-pointer. oprofile is started with --callgraph=25. report I run with --callgraph. the call graph is produced but it's only includes self time, which is not much use what am ...

Intrinsics program (SSE) - g++ - help needed

Hi all, This is the first time I am posting a question on stackoverflow, so please try and overlook any errors I may have made in formatting my question/code. But please do point the same out to me so I may be more careful. I was trying to write some simple intrinsics routines for the addition of two 128-bit (containing 4 float variabl...

Find the "name" of a library (-L -l switches)

Being fairly new to C++ I have a question bascially concerning the g++ compiler and especially the inclusion of libraries. Consider the following makefile: CPPFLAGS= -I libraries/boost_1_43_0-bin/include/ -I libraries/jpeg-8b-bin/include/ LDLIBS= libraries/jpeg-8b-bin/lib/libjpeg.a # LDLIBS= -L libraries/jpeg-8b-bin/lib -llibjpeg all: ...

How to change version of g++ compiler from 4.1.2 to 4.5 ?

Hi, I am new to linux and unaware of how to change the version of g++ to 4.5 . I need to do that in order to execute c++0x programs. Thanks. ...

C++ Templates: Convincing self against code bloat

I have heard about code bloats in context of C++ templates. I know that is not the case with modern C++ compilers. But, I want to construct an example and convince myself. Lets say we have a class template< typename T, size_t N > class Array { public: T * data(); private: T elems_[ N ]; }; template< typename T, size_t N > ...

Hiding instantiated templates in shared library created with g++

I have a file that contains the following: #include <map> class A {}; void doSomething() { std::map<int, A> m; } When compiled into a shared library with g++, the library contains dynamic symbols for all the methods of std::map<int, A>. Since A is private to this file, there is no possibility that std::map will be instantiated i...

what does macosx-version-min imply?

When I pass compiler flag "-mmacosx-version-min=10.5", what does it mean? I think it implies the result binary is x86, not ppc, but is it 32 bits or 64 bits? I'm compiling on snow leopard, so default output binary is 64 bits. I'm not passing -universal, it's not 32bit-64bit universal binary, I think. ...

Strange overloading rules in C++

I'm trying to compile this code with GCC 4.5.0: #include <algorithm> #include <vector> template <typename T> void sort(T, T) {} int main() { std::vector<int> v; sort(v.begin(), v.end()); } But it doesn't seem to work: $ g++ -c nm.cpp nm.cpp: In function ‘int main()’: nm.cpp:9:28: error: call of overloaded ‘sort(std::vector<...

Using Qt with custom MinGW

Hi, I don't know if this question would fit better on superuser.com, but since it's rather compiler related, I give it a try here. I have to use Qt with a specific version of gcc (4.5). I downloaded the last official Qt release for Windows (Vista, 32 bits version) and didn't install the shipped MinGW version; I just installed the Qt li...

g++ SSE intrinsics dilemma - value from intrinsic "saturates"

Hi, I wrote a simple program to implement SSE intrinsics for computing the inner product of two large (100000 or more elements) vectors. The program compares the execution time for both, inner product computed the conventional way and using intrinsics. Everything works out fine, until I insert (just for the fun of it) an inner loop befo...

warning: (Internal error: pc 0x804a6b0 in read in psymtab, but not in symtab.) g++

I am trying to debug a program using ddd. When I try to enter any function, or within main() itself, I get the following warning: warning: (Internal error: pc 0x804a6b0 in read in psymtab, but not in symtab.) This warning flashes whenever I try to move to another instruction using 'n' or enter or leave a function. I have tried to...

GNU C++ how to check when -std=c++0x is in effect?

My system compiler (gcc42) works fine with the TR1 features that I want, but trying to support newer compiler versions other than the systems, trying to accessing TR1 headers an #error demanding the -std=c++0x option because of how it interfaces with library or some hub bub like that. /usr/local/lib/gcc45/include/c++/bits/c++0x_warning....

GCC doesn't like C++ style casts with spaces

I am porting some C++ code to GCC, and apperantly it isn't happy with C++ style casting when sapces are involved, as in unsigned int(-1), long long(ShortVar) etc... It gives an error: expected primary-expression before 'long'. Is there any way to make peace with GCC without going over each one of those and rewrite in c-style? ...