gcc

static initialization of Template classes for singleton object

Hi, We have a singleton template class as defines below template<class T> class Singleton{ T& reference(){ return objT; } private: T objT; }; And another user defined class which uses this singleton class TestClass{ static Singleton<TestClass> instance; static TestClass * getPointer() ...

Dump memory of a process

Hi, When reading the /proc/$PID/maps you get the mapped memory regions. Is ther a way to dump one of this regions? $ cat /proc/18448/maps ...[snip]... 0059e000-005b1000 r-xp 00000000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0 005b1000-005b2000 r--p 00012000 08:11 40 /usr/local/lib/libgstlightning.so.0.0.0 005b200...

Automatically choosing object files for compilation

I have recently begun writing unit tests (using GoogleTest) for a C++ project. Building the main project is fairly simple: I use GCC's -MM and -MD flags to automatically generate dependencies for my object files, then I link all of the object files together for the output executable. No surpirses. But as I'm writing unit tests, is the...

Prepending (w/out newlines) to an auto-generated dependency list for Makefiles.

Not sure if the title makes sense... so I'll elaborate a bit. I'm toying with this makefile that uses gcc's auto-dependency list generator. At the same time, I wanted to keep a nice sorted directory structure that separates source, headers, and resources. The layout's nice and simple like so MAIN src include objects dependencies ...

Why is a GCC cross compile not building `crti.o`?

In an attempt to build a gcc 4.x.x cross compiler for arm, I'm stuck at a missing crti.o file in the $BUILD_DIR/gcc subdirectory. An strace on the top level Makefile shows that the compiled xgcc is calling the cross-linker ld with "crti.o" as an argument. I'm assuming that if the cross linking ld is being called, the native /usr/lib/cr...

Dynamic linking a library - successful when executable is built, same setup fails when another .so is made

I am writing a numerical code, in which I would like to use a third-party-written shared library. I am working on an x86_64 k8 architecture, under CentOS. The desired target that I would like to build would be either a Python or a Matlab extension module, which are, from what I understand, gcc-built dynamically-linked shared libraries, w...

C/C++ memory footprint, per source file

In C programming, is there any way to determine how much a single source code file contributes to the final memory footprint? Let us assume a simple C-program consisting of source files test1.c, test2.c, test3.c, and so on. The environment is Linux and the complier gcc. With objdump and readelf can be seen see the total footprint and h...

How to force OpenMPI to use GCC instead of ICC? Is recompiling OpenMPI necessary?

I have a C-code for parallel computing written for gcc, and I want to compile it on a cluster, which apparently uses icc via mpicc. Correcting the code to be icc-friendly seems to be too time-demanding, so I wonder if I can ask OpenMPI to use gcc instead. I don't have the admin rights on that cluster, and I would actually prefer to do no...

How do I debug C++0x programs in MacPorts gcc 4.5?

I have a simple c++ program I am trying to debug, but gdb cannot find the object file for the libraries (or no debug info is available), and it does not seem able to find the debug symbols for my executable either. I am on OSX 10.5.8, with macports, and I compile my code with g++-mp-4.5 -Wall -pedantic -std=c++0x -g -ggdb -I/opt/loc...

C++ error in ios_base.h

/usr/include/c++/4.4/bits/ios_base.h: In member function ‘std::basic_ios >& std::basic_ios >::operator=(const std::basic_ios >&)’: /usr/include/c++/4.4/bits/ios_base.h:793: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)’ is private /usr/include/c++/4.4/iosfwd:47: error: within this context /usr/include/c++...

How to pass -libm to MPICC? libimf.so: warning: feupdateenv is not implemented and will always fail

I am a newbie who tries to compile a program via mpicc replacing icc with gcc. I have already discovered, that I need to use the following command to compile $ OMPI_CC=gcc make However, I get the following error message (which is well-known) /opt/intel/fce/9.1.036/lib/libimf.so: warning: warning: feupdateenv is not implemented and wi...

Invalid operands to binary

Hi, I have a method to check weather a number is even or odd: -(BOOL)numberIsEven:(unsigned int *)x { if (x & 1) { return TRUE; } else { return FALSE; } } however whenever I compile it I get the error: Invalid operands to binary % So it's compiling into assembly as a modulus function and failing, somehow, however if...

vsnprintf and gcc

Hello, I have the fallowing statement: vsnprintf(target, size - 1, "%ls_%ls", str16_1, str16_2); Do you know why this fails on gcc? I used this on Windows like this: vsnprintf(target, size - 1, "%S_%S", str16_1, str16_2); and it's working as expected. On gcc documentation I found that %S is synonym with %ls, but I must not use it...

Is it safe to replace GCC's system-level C++ runtime with a version from newer GCC?

Linux C++ programs build with GCC link against libgcc_s.so.1 and libstdc++.so.6 libraries, each of which contains multiple ABIs: newer versions contain ABIs from previous version plus new ones. GCC ABI policy document says programs build against older runtime should be able to be run with the new runtime. So, theoretically, older binarie...

Use -isystem instead of -I with CMake

Is there any way in CMake to force a path specified via include_directories (or perhaps through a different function) to use the -isystem flag instead of the -I flag when building with gcc? See http://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html#Directory-Options for details on -I and -isystem. ...

__attribute__((init_priority(X))) in GCC

I'm using __attribute__((init_priority(X))) in GCC like this: Type1 __attribute__ ((init_priority (101))) name1 = value1; Type2 __attribute__ ((init_priority (102))) name2 = value2; in different source files. Let's say file1.cpp and file2.cpp. If I use this in same library it works as expected, name1 is initialized before name2 but i...

"/usr/bin/ld: cannot find -lz"

I am trying to compile android source code under ubuntu 10.04. I get the following error saying "/usr/bin/ld: cannot find -lz". Can you please tell me how can I fix it? what does "can't find -lz" mean? external/qemu/Makefile.android:1101: warning: overriding commands for target `external/qemu/android/avd/hw-config-defs.h' external/qemu...

gcc Linkage option -L: Alternative ways how to specify the path to the dynamic library

If I compile my source code with "-L." the dynamic library libmd5.so can be found. gcc main.c -g -O2 -Wall -o main -L. -lmd5 -lcr But if I leave the "-L."-option away, the linker does not find the dynamic library. How can I change that without having to invoke "-L."? (additional info libmd5.so and libmd5.so.1.0.1 are located in /hom...

Execute commands if compiling fails with Make

With GNU Make and one of the compilers in gcc: Is it possible to execute commands if (and only if) the compiling fails? ...

Useful GCC flags for C

Beyond setting -Wall, and setting -std=XXX, what other really useful, but less known compiler flags are there for use in C? I'm particularly interested in any additional warnings, and/or and turning warnings into errors in some cases to absolutely minimize any accidental type mismatches. ...