Questions tagged [gcc]

GCC is the GNU Compiler Collection. It's the de facto standard compiler for C, C++, Go, Fortran, and Ada on Linux and supports many other languages and platforms as well.

GCC is the GNU Compiler Collection, a collection of free software compilers. It is a key component of the GNU Toolchain.

GCC includes an optimizing C compiler that is the most commonly used C compiler on Linux. GCC also includes front ends for C++ (including full support for C++17), Objective-C, Fortran, Ada, and Go, as well as libraries for these languages (libstdc++, libgfortran, ...). It supports many architectures.

GCC sources are available via the Git repository. Major decisions about GCC are made by the steering committee, guided by the mission statement.

See also GCC online documentation and the home page, and release dates.

40905 questions
149
votes
5 answers

Why does the enhanced GCC 6 optimizer break practical C++ code?

GCC 6 has a new optimizer feature: It assumes that this is always not null and optimizes based on that. Value range propagation now assumes that the this pointer of C++ member functions is non-null. This eliminates common null pointer checks but…
boot4life
  • 4,966
  • 7
  • 25
  • 47
149
votes
5 answers

Explicit specialization in non-namespace scope

template class CConstraint { public: CConstraint() { } virtual ~CConstraint() { } template void Verify(int position, int constraints[]) { } template <> void…
Mark
  • 2,181
  • 3
  • 19
  • 28
148
votes
3 answers

How to prevent gcc optimizing some statements in C?

In order to make a page dirty (switching on the dirty bit in the page table entry), I touch the first bytes of the page like this: pageptr[0] = pageptr[0]; But in practice gcc will ignore the statement by dead store elimination. In order to prevent…
ZelluX
  • 69,107
  • 19
  • 71
  • 104
148
votes
5 answers

How do I make a simple makefile for gcc on Linux?

I have three files: program.c, program.h and headers.h. program.c includes program.h and headers.h. I need to compile this on Linux using gcc compiler. I'm not sure how to do this. Netbeans created one for me, but it's empty.
user69514
  • 26,935
  • 59
  • 154
  • 188
146
votes
21 answers

CUDA incompatible with my gcc version

I have troubles compiling some of the examples shipped with CUDA SDK. I have installed the developers driver (version 270.41.19) and the CUDA toolkit, then finally the SDK (both the 4.0.17 version). Initially it didn't compile at all giving: error…
fbielejec
  • 3,492
  • 4
  • 27
  • 35
145
votes
5 answers

Where is PATH_MAX defined in Linux?

Which header file should I invoke with #include to be able to use PATH_MAX as an int for sizing a string? I want to be able to declare: char *current_path[PATH_MAX]; But when I do so my compiler (Clang/LLVM on Linux) issues the following…
haziz
  • 12,994
  • 16
  • 54
  • 75
142
votes
19 answers

/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found

How can I get GLIBCXX_3.4.15 in Ubuntu? I can't run some programs that I'm compiling. When I do: strings /usr/lib/libstdc++.so.6 | grep GLIBC I…
Chris
  • 6,642
  • 7
  • 42
  • 55
141
votes
11 answers

Is using an outdated C compiler a security risk?

We have some build systems in production which no one cares about and these machines run ancient versions of GCC like GCC 3 or GCC 2. And I can't persuade the management to upgrade it to a more recent: they say, "if ain't broke, don't fix it".…
Calmarius
  • 18,570
  • 18
  • 110
  • 157
140
votes
6 answers

Undefined reference to `pow' and `floor'

I'm trying to make a simple fibonacci calculator in C but when compiling gcc tells me that I'm missing the pow and floor functions. What's wrong? Code: #include #include int fibo(int n); int main() { printf("Fib(4) =…
kettlepot
  • 10,574
  • 28
  • 71
  • 100
138
votes
2 answers

What is the -fPIE option for position-independent executables in gcc and ld?

How will it change the code, e.g. function calls?
osgx
  • 90,338
  • 53
  • 357
  • 513
138
votes
5 answers

GDB: How to print the current line or find the current line number?

The list command prints a set of lines, but I need one single line: where I currently am and where an error has probably occurred.
Boris Burkov
  • 13,420
  • 17
  • 74
  • 109
137
votes
6 answers

Why does integer overflow on x86 with GCC cause an infinite loop?

The following code goes into an infinite loop on GCC: #include using namespace std; int main(){ int i = 0x10000000; int c = 0; do{ c++; i += i; cout << i << endl; }while (i > 0); cout << c <<…
Mysticial
  • 464,885
  • 45
  • 335
  • 332
137
votes
2 answers

Why do I get "a label can only be part of a statement and a declaration is not a statement" if I have a variable that is initialized after a label?

I have the following simplified code: #include int main () { printf("Hello "); goto Cleanup; Cleanup: char *str = "World\n"; printf("%s\n", str); } I get an error because a new variable is declared after the label. If I…
user1952500
  • 6,611
  • 3
  • 24
  • 37
135
votes
3 answers

What does -fPIC mean when building a shared library?

I know the '-fPIC' option has something to do with resolving addresses and independence between individual modules, but I'm not sure what it really means. Can you explain?
Sasha
135
votes
4 answers

How many GCC optimization levels are there?

How many GCC optimization levels are there? I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4 If I use a really large number, it won't work. However, I have tried gcc -O100 and it compiled. How many optimization levels are there?
neuromancer
  • 53,769
  • 78
  • 166
  • 223