gcc

changing search-dirs for $ sudo gcc

On OS X I'm trying to install the zlib prerequisite for haskell's Cabal. I get this error: $ sudo ./Setup build Preprocessing library zlib-0.5.0.0… ld: library not found for -lgmp collect2: ld returned 1 exit status linking dist/build/Codec/Compression/Zlib/Stream_hsc_make.o failed command was: /usr/bin/gcc -lz -L/sw/lib/ghc-6.8.3/lib/...

GCC function attributes vs caching

I have one costly function that gets called many times and there is a very limited set of possible values for the parameter. Function return code depends only on arguments so the obvious way to speed things up is to keep a static cache within the function for possible arguments and corresponding return codes, so for every combination of ...

Static link of shared library function in gcc

How can I link a shared library function statically in gcc? ...

linking a shared library using gcc

Hello, I have a shared library (*.so) created using Real View Compiler Tools (RVCT 3.2) on windows target. Then i try to link this *.so file with my application using gcc on linux system. What is the gcc option to link this shared library with my application linux? My question is the option -shared used as gcc -shared myfile.so is u...

What is the equivalent of _emit on Linux?

I'm trying to port some assembly code written in Visual Studio into GNU inline assembly on Linux. The original code uses _emit which MSDN describes as a pseudo instruction and explains as: The _emit pseudoinstruction is similar to the DB directive of MASM. You use _emit to define a single immediate byte at the current location in the...

Adding a pass to gcc ?

Hi, Has anybody added a pass to gcc ? or not really a pass but adding an option to do some nasty things... :-) ... I still have the same problem about calling a function just before returning from another...so I would like to investigate it by implementing something in gcc... Cheers. EDIT: Adding a pass to a compiler means revisiting...

What's the first double that deviates from its corresponding long by delta?

I want to know the first double from 0d upwards that deviates by the long of the "same value" by some delta, say 1e-8. I'm failing here though. I'm trying to do this in C although I usually use managed languages, just in case. Please help. #include <stdio.h> #include <limits.h> #define DELTA 1e-8 int main() { double d = 0; // c...

jstack equavalent in C++

Hi, jstack is very helpful to me in checking stack traces of live running processes. Is there any tool in C++ to do this task. I am working with Solaris/GCC compilers. Actually GDB/DBX can do that. But my process is hanging some times that to very rarely. So when that is hanging I want to know where it is going wrong. Just track that ...

#ifdef for 32-bit platform

In an application I maintain, we've encountered a problem with file descriptor limitations affecting the stdlib. This problem only affects the 32-bit version of the standard lib. I have devised a fix for my code and would like to implement it, but only when compiling for 32-bit executable. What pre-processor symbol can I #ifdef for to d...

Why does GCC not find my non-template function? ("no matching function for call to...")

In MSVC 2008, I have the following code: class Foo { // Be a little smarter about deriving the vertex type, to save the user some typing. template<typename Vertex> inline void drawVertices( Elements vCount, RenPrim primitiveType, PixMaterial *mtl, Vertex const *vertices) { this->drawVertices(vCount, primitiveType, mtl, ve...

Compiling C++ Programs with Emacs on Windows

I've been using Emacs for quite some time for basic text editing but as of today I am attempting to use it for c++ compilation. I have looked for the past few hours about how to go about this but I keep hitting roadblocks in their techniques (I think some of this is having to do with the tutorials being outdated). Basically, all I want ...

warning: the use of `mktemp' is dangerous

Hello! How can I suppress following warning from gcc linker: warning: the use of mktemp' is dangerous, better use mkstemp' I do know that it's better to use mkstemp() but for some reason I have to use mktemp() function. ...

How to allow more memory and avoid stack overflow on lots of recursion?

I'm testing the timing of an algorithm that does lots of recursive calls. My program dies at about 128k recursive calls, and this takes only .05 seconds. I'd like to allow more memory to have longer timings in my analysis. I'm running linux and using gcc. Is there a system call, or environment variable, or gcc flag, or wrapper, or someth...

GCC Inline Assembly: Jump to label outside block

When using inline assembly under MSVC, one is allowed to jump outside of the assembly block by referencing a label in the C/C++ code, as explained in this MSDN article. Can such thing be done when using inline assembly under GCC? Here's an example of what I'm trying to accomplish: __asm__ __volatile__ ( " /* assembly code */ " " j...

How to get rid of gcc assembler warning "setting incorrect section attributes for .init" in C code?

I have the following C code: struct myStruct_t { const char m_name[60]; const uint32_t m_data; }; const struct myStruct_t myStruct __attribute__(( __aligned__( 64 ), section(".init") )) = { "myName", (uint32_t)&someOtherStruct }; When I compile in gcc 4.1.1 (for PS3), I get the warning: 1>c:/t...

Realistic usage of the C99 'restrict' keyword?

I was browsing through some documentation and questions/answers and saw it mentioned. I read a brief description, stating that it would be basically a promise from the programmer that the pointer won't be used to point somewhere else. Can anyone offer some realistic cases where its worth actually using this? ...

How do I turn off erroneous float/long error messages from gcc.

I recently was making a change to to our codebase from float to long for some variables, and discovered that there were no error messages generated by the compiler in areas I knew were still wrong. This led me to add -Wconversion to the compiler flags. But, oops, this leads to some spurious error messages. In the snippet below, I get er...

Why doesn't auto_ptr construction work using = syntax

I ran into a compiler error that didn't make much sense to me: #include <memory> using namespace std; auto_ptr<Table> table = db->query("select * from t"); error: conversion from 'Table*' to non-scalar type 'std::auto_ptr< Table>' requested However, the following line does work: auto_ptr<Table> table(db->query("select * from t")); ...

'comparison is always true due to limited range of data type' warning in C?

I have the following code //Point.h #define WIDTH 8 #define HEIGHT 8 typedef struct Point { char x; char y; } Point; //Board.c #include <stdbool.h> // Some other functions that we don't care about... bool inBounds(Point * p) { return p->x >= 0 && p->x <= WIDTH && p->y >= 0 && p->y <= HEIGHT; } When I compile th...

What is the difference between make and gcc?

The last sentence in the article caught my eye [F]or C/C++ developers and students interested in learning to program in C/C++ rather than users of Linux. This is because the compiling of source code is made simple in GNU/Linux by the use of the 'make' command. I have always used gcc to compile my C/C++ programs, whereas...