problem about gcc4-Collection of common programming errors


  • Konrad Rudolph
    c++ osx templates undefined-reference gcc4
    PremiseI’m using a C library (from C++) which provides the following interface:void register_callback(void* f, void* data); void invoke_callback();ProblemNow, I need to register a function template as a callback and this is causing me problems. Consider the following code:template void my_callback(void* data) { … }int main() {int ft = 42;register_callback(reinterpret_cast(&my_callback), &ft);invoke_callback(); }This gives me the following linker error (using g++ (GCC) 4.5.1 on OS X but works on most other combinations of compiler version / platform):Undefined symbols for architecture x86_64:”void my_callback(void*)”, referenced from:

  • bgp2000
    cmake linker-error gcc4
    I am developing a library and need to make sure it compiles with 4.1.2(I know, it brings me no pleasure). So on a Fedora 14 Machine I downloaded, compiled and installed GCC41.Now in CMake I only change the following to variables CMAKE_CXX_COMPILER=/opt/gcc41/bin/c++41 CMAKE_C_COMPILER=/opt/gcc41/bin/gcc41It compiles fine,

  • squashed.bugaboo
    c++ python linux boost gcc4
    Ugh! I have hit one of those errors where I am really clueless. I have built/installed Python (2.7.1) and I’ve built/installed boost (1.44.0) against that version of python. I don’t see any errors in my boost build, everything goes through fine. When I turn to d

  • A Fog
    c++ c overflow integer-overflow gcc4
    Possible Duplicate:Best way to detect integer overflow in C/C++ No, this is not a duplicate. The issue is the same but the question is different.The gcc compiler can optimize away an overflow check (with -O2), for example:int a, b; b = abs(a); // will overflow if a = 0x80000000 if (b < 0) printf(“overflow”); // optimized awayThe gcc people argue that this is not a bug. Overflow is undefined behavior, according to the C standard, which allows the compiler to do anything. Apparently, anything includes assuming that overflow never happens. Unfortunately, this allows the compiler to optimize away the overflow check.The safe way to check for overflow is described in a recent CERT paper. This paper recommends doing something like this before adding two integers:if ( ((si1^si2) | (((si1^(~(si1^si2) & INT_MIN)) + si2)^si2)) >= 0) { /* handle error condition */ } else {sum = si1 + si2; }Apparently, you have to do something like this before every +, -, *, / and other operations in a series of calculations when you want to be sure that the result is valid. For example if you want to make sure an arra

  • Arne Bergene Fossaa
    gcc gcc4
    I am observing a difference when trying to do the same operation on GCC 4.4 and GCC 4.5. Because the code I am doing this with is proprietary, I am unable to provide it, but I am observing a similar failure with this simple test case.What I am basically trying to do is have one shared library (libb) depend on another shared library (liba). When loading libb, I assume that liba should be loaded as well – even though libb is not necessarily using the symbols in liba.What I am observing is when I compile with GCC 4.4, I observe that the lib

  • Mat
    c linker gentoo gcc4
    I’m on gentoo linux with GCC 4.4.5 installed. I can compile and link such program without any errors using gcc main.c -o main, and the command ./main returns result correctly. [main.c] #include #include int main(void) {double c = ceil(2.5);printf(“The cei

  • Kunal P.Bharati
    gcc gcc4
    I am using Brian Gladman’s library for EAX encryption in one of my project. The problem is the code works on my loc

  • Wade
    c exception compiler-optimization gcc4
    Using gcc 4.7:$ gcc –version gcc (GCC) 4.7.0 20120505 (prerelease)Code listing (test.c):#include struct test {int before;char start[0];unsigned int v1;unsigned int

  • Chung-Ju Wu
    c c99 gcc4 sequence-points
    There is a code fragment that GCC produce the result I didn’t expect:(I am using gcc version 4.6.1 Ubuntu/Linaro 4.6.1-9ubuntu3 for target i686-linux-gnu)[test.c]#include int *ptr;int f(void) {(*ptr)++;return 1; }int main() {int a = 1, b = 2;ptr = &b;a = b++ + f() + f() ? b : a;printf (“b = %d\n”, b);return a; }In my understanding, there is a sequence point at function call. T

  • Yuji
    linker gfortran gcc4
    I’m trying to compile a code (not mine) that consists of mixed Fortran and C source files, which are compiled into a library. This library can either be linked against directly, or (more usefully) driven from a python class. I have previously successfully built the code as 32-bit with g77 and gcc, but I’ve encountered a situation in which the code uses big chunks of memory, and needs to be 64-bit.I’ve attempted to build as both 64-bit only, or as a universal b

  • user1242145
    header-files undefined-reference gcc4 perfect-hash
    I am using gcc 4.4.3 on ubuntu. I installed cmph library tools 0.9-1 using commandsudo apt-get install libcmph-toolsNow, when I tried to compile example program vector_adapter_ex1.c , gcc is able to d

  • Vladimir Still
    gcc arm gcc4
    I’m trying to compile GCC on synology DS109 NAS disk which is powered by Marvell Kirkwood mv6281 ARM Processor. It is currently running quite outdated GCC 4.2.3 which is the newest vesion that I found for it in binaries.I tried GCC 4.7.1 and 4.6.3 both with same result during make phase:build/genflags.o build/rtl.o build/read-rtl.o build/ggc-none.o build/vec.o build/min-insn-modes.o build/gensupport.o build/print-rtl.o build/read-md.o build/errors.o ../build-armv5tel-unknown-linux-gnueabi/libiberty/libiberty.a build/rtl.o: In function `rtvec_alloc’: /volume1/public/gcc-4.6.3/build/gcc/../../gcc-4.6.3/gcc/rtl.c:153: undefined re

  • Claire Huang
    c++ compiler ubuntu g++ gcc4
    I tried to install gcc 4.5 on ubuntu 10.04 but failed. Here is a compile error that I don’t know how to solve. Is there anyone successfully install the latest gcc on ubuntu? Following is my steps and the error message, I’d like to know where is the problem….Step1: download these files:gcc-core-4.5.0.tar.gz gcc-g++-4.5.0.tar.gz gmp-4.3.2.tar.bz2 mpc-0.8.1.tar.gz mpfr-2.4.2.tar.gzStep2: Unzip above filesStep3: move gmp, mpc, mpfr to the gcc-4.5.0/ directory.mv gmp-4.3.2 gcc-4.5.0/gmp mv mpc-0.8.1 gcc-4.5.0/mpc mv mpf

  • Shredderroy
    c hashtable glib gcc4
    I have the following simple lines of code:#include #include void my_func () {GHashTable htbls[3]; /* ASSU

  • boundless08
    debian gcc4 hiphop
    I’m having trouble installing gcc 4.6.3 on Debian squeeze. 4.4 is currently installed but I need 4.6.x to run php-hiphop. I’ve tried looking for similar problems but haven’t found any with the error I have.I install using these instructions:wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.6.3/gcc-4.6.3.tar.gz tar -xzvf gcc-4.6.3.tar.gz cd gcc-4.6.3 ./contrib/download_prerequisites cd .. mkdir objdir cd objdir £PWD/../gcc-4.6.3/configure –prefix=/opt/gcc-4.6.3 make make installon the make command everything seems to be going fine for a good 20 or more minutes then, BLAMO! This pops up:make[5]: Entering directory `/root/objdir/x86_64-unknown-linux-gnu/32/libgcc’ # If this is the top-level multilib, build all the other # multilibs. /root/objdir/./gcc/xgcc -B/root/objdir/./gcc/ -B/opt/gcc-4.6.3/x86_64-unknown-linux-gnu/bin/ -B/opt/gcc-4.6.3/x86_64-unknown-linux-gnu/lib/ -isystem /opt/gcc-4.6.3/x86_64-unknown-linux-gnu/include -isystem /opt/gcc-4.6.3/x86_64-unknown-linux-gnu/sys-include -g -O2 -m32 -O2 -g -O2 -DIN_GCC -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include

  • djin
    osx gcc linker gcc4
    I am trying to install gcc-4.0.1 on a mac with Darwin 12.1.0 . I did the configuration with ./configure –prefix=/usr/local/gcc-4.0.1 –enable-languages=c,c++ . It give

Originally posted 2013-11-09 21:42:05.