Questions tagged [compiler-flags]

Parameters that may be passed to a compiler affecting how compilation is carried out. These can have a variety of effects on the paths searched for external dependencies, optimization level, how source code is interpreted, code checks that are performed and preprocessor directives.

Parameters that may be passed to a compiler affecting how compilation is carried out. These can have a variety of effects on the paths searched for external dependencies, optimization level, how source code is interpreted, code checks that are performed and preprocessor directives.

479 questions
289
votes
5 answers

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 proven to be necessary. Is this true, and if so, why?…
Matt Dunn
  • 5,106
  • 6
  • 31
  • 55
198
votes
5 answers

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 compiling on. But how can I check which flags is…
vartec
  • 131,205
  • 36
  • 218
  • 244
177
votes
24 answers

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 warnings into errors in some cases to absolutely…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
175
votes
8 answers

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 conjunction with -ansi, this tells the compiler to be adhere…
huahsin68
  • 6,819
  • 20
  • 79
  • 113
156
votes
3 answers

Difference between -pthread and -lpthread while compiling

What is the difference between gcc -pthread and gcc -lpthread which is used while compiling multithreaded programs?
Vishnuraj V
  • 2,819
  • 3
  • 19
  • 23
128
votes
10 answers

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/boost/system/error_code.hpp: At global…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
76
votes
8 answers

How do I force gcc to inline a function?

Does __attribute__((always_inline)) force a function to be inlined by gcc?
HaltingState
  • 1,810
  • 1
  • 20
  • 22
72
votes
8 answers

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 T add(T a, T b) { return a + b; } When I call: add(10, 2); ... I would…
Vineel Kumar Reddy
  • 4,588
  • 9
  • 33
  • 37
69
votes
2 answers

Does set_target_properties in CMake override CMAKE_CXX_FLAGS?

At the beginning of my CMake project, I'm setting general compilation flags in the variable CMAKE_CXX_FLAGS, like set(CMAKE_CXX_FLAGS "-W -Wall ${CMAKE_CXX_FLAGS}") Later on, I need to append additional configuration-specific compilation flags…
Milan Hanus
  • 714
  • 1
  • 5
  • 7
53
votes
11 answers

Changing CMAKE_CXX_FLAGS in project

I have the following content in my CMakeLists.txt: project( Matfile ) SET ( CMAKE_CXX_FLAGS "-std=c++0x" ) set ( SOURCES "foo.cpp" "bar.cpp" ) add_library( Matfile ${SOURCES} ) As you may imagine, what I want to…
Spiros
  • 2,156
  • 2
  • 23
  • 42
49
votes
5 answers

@JvmDefault and how add compiler option

I need to make a default void method in a Kotlin interface. I ran into a problem and a hint said Usage of @JvmDefault is only allowed with -Xjvm-default option. Where do I need to write this Xjvm-default?
Evgesha
  • 491
  • 1
  • 4
  • 4
42
votes
1 answer

What's the "DNS_BLOCK_ASSERTIONS" (C compiler flag)?

What's the "DNS_BLOCK_ASSERTIONS" (C compiler flag)?
eonil
  • 83,476
  • 81
  • 317
  • 516
39
votes
6 answers

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.
smallB
  • 16,662
  • 33
  • 107
  • 151
37
votes
6 answers

gcc optimization flags for Xeon?

I'd want your input which gcc compiler flags to use when optimizing for Xeons? There's no 'xeon' in mtune or march so which is the closest match?
Eugene Bujak
  • 1,591
  • 2
  • 14
  • 14
37
votes
3 answers

How does GCC's '-pg' flag work in relation to profilers?

I'm trying to understand how the -pg (or -p) flag works when compiling C code with GCC. The official GCC documentation only states: -pg Generate extra code to write profile information suitable for the analysis program gprof. You must use this…
Trevor
  • 1,858
  • 4
  • 21
  • 28
1
2 3
31 32