gcc

Recipe for compiling binutils & gcc together?

Greetings, According the the gcc build instructions you can build binutils concurrently with building gcc (as well as gmp,mpc,etc). Here's what that page says : If you also intend to build binutils (either to upgrade an existing installation or for use in place of the corresponding tools of your OS), unpack the binutils di...

c++: generate function call tree

I want to parse current c++ files in a project and list out all the methods/functions in it and then generate the function call and caller trees. F.g. you can refer how doxygen generates the call tree. I have checked gccxml but it doesn't list the functions called from another function. Please suggest me some lightweight tools (open so...

What is causing this segmentation fault while using SSE instructions?

This problem is driving me a bit crazy. The code seems to be segmentation faulting for no good reason: #define MULT_FLOAT4(X, Y) ({ \ asm volatile ( \ "movups (%0), %%xmm0\n\t" \ "mulps (%1), %%xmm0\n\t" \ "movups %%xmm0, (%1)" \ :: "r" (X), "r" (Y)); }) int main(void) { int before; float a[4...

GCC - shouldn't a warning be issued?

I've recently set up a MinGW + MSYS environment on my laptop to check how things are with Netbeans C/C++ support. Everything seems to work fine, however, during my testing I have noticed a difference between GCC and Microsoft's cl.exe compiler. Here's a sample program: #include <stdio.h> #include <stdlib.h> #include <limits.h> int mai...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the .txt and just have it included? Something like a PHP include! Does gcc allow this? ...

Getting rid of pre-compiled headers

OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds. How does one get rid of Pre-compiled headers, conceptually? do you take the contents of a .pch and move them to a core.h and include that in all of your classes .h files? I want to mo...

strlen() implementation in gcc

Can anyone point me to the definition of strlen() in GCC? I've been grepping release 4.4.2 for about a half hour now (while Googling like crazy) and I can't seem to find where strlen() is actually implemented. ...

Benchmarking SSE instructions

I'm benchmarking some SSE code (multiplying 4 floats by 4 floats) against traditional C code doing the same thing. I think my benchmark code must be incorrect in some way because it seems to say that the non-SSE code is faster than the SSE by a factor of 2-3. Can someone tell me what is wrong with the benchmarking code below? And perhap...

Generate assembler code from C file in linux

Hi I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I'm getting errors. I'm trying to build an assembler program from 3 different programs prog1.c prog2.c prog.h Is it correct to do gcc -S prog1.c prog2.c prog.h? Seems that i...

options superseded in gcc

In a Makefile of a library I am trying to build, there are a few lines specify the options to gcc: CFLAGS += -I$(CURDIR) -pedantic -std=c89 -O3 CFLAGS += -Wall -Wno-unused-function -Wno-long-long CFLAGS += $(if $(DEBUG), -O0 -g) If DEBUG exists, there will be both -O3 and -O0 -g in CFLAGS. But -O0 and -O...

GCC: Force a function call after every instruction (for multithreaded testing)?

Hi, I'm trying to test a rather threading-sensitive area in my program and was wondering if there's a way to force gcc to insert a call after every instruction it emits so that I can manually yield to a different thread? Thanks, Robert ...

fcntl issues compiling C++

{net04:~/xxxx/wip} gcc -o write_test write_test.c In file included from write_test.c:4: global.h:10: warning: `b' initialized and declared `extern' This code uses fcntl.h and the file-handling functions defined - like open(), write(), close() etc.. The code compiles and works as intended. {net04:~/xxxx/wip} gcc -o write_test write_t...

How to catch exception thrown from library in GCC C++?

When i use dlopen to dynamically load a library it seems i can not catch exceptions thrown by that library. As i understand it it's because dlopen is a C function. Is there another way to dynamically load a library that makes it possible to catch exceptions thrown by the lib in GCC? In Windows you can use LoadLibrary but for Linux i ha...

-isystem for MS Visual Studio C++ Compiler

I usually like to have a lot of warnings enabled when programming. However, some libraries contains code that easily causes warnings (.., python, Qt, ..). When compiling with gcc I can just use -isystem instead of -I to silence that. How can I do the same with the MS compiler? I know of the warning #pragma, but I would like a solution th...

How do modern optimizing compilers determine when to optimize?

How do modern optimizing compilers determine when to apply certain optimizations such as loop unrolling and code inlining? Since both of these affect caching, naively inlining functions with less than X lines, or whatever other simple heuristic, is likely to generate worse performing code. So, how do modern compilers deal with this? I'...

C++ linker - Lack of duplicate symbols

Why does the following code not give me a duplicate symbol linker error for Impl? I ran across this problem in some code I inherited and I'm recreating a shorter version here for simplicity. I have two classes, Foo and Bar, that each define a different version of the same struct (Impl) in each of their .cpp files. So Foo.cpp and Bar.c...

gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared library, but I doesn't seem to need the -fPIC option. Well, my question is, why does -fPIC change gcc optimizations ? Do I need to keep -fPIC ...

Create a shared lib using another shared lib

I have a shared library "libwiston.so". I am using this to create another shared library called "libAnimation.so", which will be used by another project. Now, the second library "libAnimation.so" can't be used in test code correctly. So I doubt that the creation of the second lib "libAnimation.so" is right. The gcc command to create this...

Compile C++ with Cygwin

How do I compile my C++ programs in Cygwin. I have gcc installed. What command should I use? Also, how do I run my console application when it is in a .cpp extension. I am trying to learn C++ with some little programs, but in Visual C++, I don't want to have to create a seperate project for each little .cpp file. ...

My flex/yacc program compiles differently on two different linux machines

One one machine, everything compiles fine. On another machine, it complains about the -ly option when I use gcc to create the output file. If I remove the -ly option, then it makes the program, but then it runs differently. What's happening. How can I get the program to run correctly on this linux machine? ...