111 questions
161 votes
3 answers
95k views
Difference between -pthread and -lpthread while compiling
What is the difference between gcc -pthread and gcc -lpthread which is used while compiling multithreaded programs?
13 votes
1 answer
1k views
How can I mitigate the impact of the Intel jcc erratum on gcc?
If I have a chip that is subject to the Intel jcc erratum, how I can enable the mitigation in gcc (which adjusts branch locations to avoid the problematic alignment), and which gcc versions support it?...
210 votes
6 answers
135k views
How to see which flags -march=native will activate?
I'm compiling my C++ app using GCC 4.3. Instead of manually selecting the optimization flags I'm using -march=native, which in theory should add all optimization flags applicable to the hardware I'm ...
86 votes
8 answers
104k views
How do I force gcc to inline a function?
Does __attribute__((always_inline)) force a function to be inlined by gcc?
191 votes
24 answers
108k views
What are the 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 ...
78 votes
8 answers
29k views
Can we see the templates instantiated by the C++ compiler?
Is there a way to see the compiler-instantiated code for a function template or a class template in C++? Assume I have the following piece of code: template <class T> T add(T a, T b) { ...
184 votes
8 answers
196k views
What is the purpose of using -pedantic in the GCC/G++ compiler?
This note says: -ansi: tells the compiler to implement the ANSI language option. This turns off certain "features" of GCC which are incompatible with the ANSI standard. -pedantic: used in ...
309 votes
5 answers
201k views
Is optimisation level -O3 dangerous in g++?
I have heard from various sources (though mostly from a colleague of mine), that compiling with an optimisation level of -O3 in g++ is somehow 'dangerous', and should be avoided in general unless ...
8 votes
4 answers
35k views
How to add compiler flags on codeblocks
I've been trying to compile a simple multithreaded piece of code I found online in an effort to learn how to multithread. To run this piece of code I need to use the compiler flags: -pthread and -std=...
136 votes
9 answers
316k views
How do you disable the unused variable warnings coming out of gcc in 3rd party code I do not wish to edit?
I'd like to know what switch you pass to the gcc compiler to turn off unused variable warnings? I'm getting errors out of boost on windows and I do not want to touch the boost code: C:\boost_1_52_0/...
41 votes
6 answers
44k views
Where in Qt Creator do I pass arguments to a compiler?
Where in Qt Creator do I pass arguments to a compiler? It isn't really that obvious.
28 votes
3 answers
36k views
Is it possible to set CFLAGS to a linux kernel module Makefile?
Eg: a common device module's Makefile obj-m:=jc.o default: $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules clean: $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(...
5 votes
3 answers
12k views
How to set CUDA compiler flags in Visual Studio 2010?
After persistently getting error : identifier "atomicAdd" is undefined, I've found the solution to be to compile with -arch sm_20 flag. But how to pass this compiler flag in VS 2010? I have tried like ...
29 votes
2 answers
6k views
Variables optimized out with g++ and the -Og option
When I compile my C++ program with g++ using the -Og option I see variables that are <optimized out>, and also the current line sometimes skips around. Is this behaviour expected at this ...
26 votes
6 answers
29k views
Is it possible to pass in command line variables to a bitbake build?
I have an OpenEmbedded environment using bitbake to do some builds. I wanted to get something "interactive" going on where bitbake would pause and ask for input then continue with the build but I've ...