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
134
votes
4 answers

Downcasting shared_ptr to shared_ptr?

Update: the shared_ptr in this example is like the one in Boost, but it doesn't support shared_polymorphic_downcast (or dynamic_pointer_cast or static_pointer_cast for that matter)! I'm trying to initialize a shared pointer to a derived class…
Lajos Nagy
  • 9,075
  • 11
  • 44
  • 55
133
votes
3 answers

Possible GCC bug when returning struct from a function

I believe I found a bug in GCC while implementing O'Neill's PCG PRNG. (Initial code on Godbolt's Compiler Explorer) After multiplying oldstate by MULTIPLIER, (result stored in rdi), GCC doesn't add that result to INCREMENT, movabs'ing INCREMENT to…
vitorhnn
  • 1,043
  • 1
  • 8
  • 7
133
votes
6 answers

How to tell where a header file is included from?

How can I tell where g++ was able to find an include file? Basically if I #include g++ will scan the search path, using any include options to add or alter the path. But, at the end of days, is there a way I can tell the absolute path of…
harschware
  • 13,006
  • 17
  • 55
  • 87
133
votes
3 answers

Why is a simple loop optimized when the limit is 959 but not 960?

Consider this simple loop: float f(float x[]) { float p = 1.0; for (int i = 0; i < 959; i++) p += 1; return p; } If you compile with gcc 7 (snapshot) or clang (trunk) with -march=core-avx2 -Ofast you get something very similar…
Simd
  • 19,447
  • 42
  • 136
  • 271
133
votes
7 answers

How to compile a 32-bit binary on a 64-bit linux machine with gcc/cmake

Is it possible to compile a project in 32-bit with cmake and gcc on a 64-bit system? It probably is, but how do I do it? When I tried it the "ignorant" way, without setting any parameters/flags/etc, just setting LD_LIBRARY_PATH to find the linked…
dala
  • 1,975
  • 3
  • 14
  • 15
132
votes
8 answers

error: ‘NULL’ was not declared in this scope

I get this message when compiling C++ on gcc 4.3 error: ‘NULL’ was not declared in this scope It appears and disappears and I don't know why. Why? Thanks.
jackhab
  • 17,128
  • 37
  • 99
  • 136
132
votes
1 answer

What does the -all_load linker flag do?

I can't find anywhere what the -all_load flag does when compiling Objective-C code. I have some issues uploading binaries to Apple. They say it's because I didn't use this flag. However, my code compiles even without it. Can someone help me with…
Guy Ephraim
  • 3,482
  • 3
  • 26
  • 30
130
votes
6 answers

How to install GCC piece by piece with GMP, MPFR, MPC, ELF, without shared libraries?

How do I install GCC (the GNU Compiler Collection) piece by piece, using the current version, using the correct versions of dependencies, not using a package manager (like yum, rpm, apt, dpkg), and not using shared libraries? Typical developers will…
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
129
votes
8 answers

static linking only some libraries

How can I statically link only a some specific libraries to my binary when linking with GCC? gcc ... -static ... tries to statically link all the linked libraries, but I haven't got the static version of some of them (eg: libX11).
peoro
  • 25,562
  • 20
  • 98
  • 150
128
votes
3 answers

How to create a static library with g++?

Can someone please tell me how to create a static library from a .cpp and a .hpp file? Do I need to create the .o and the .a? I would also like to know how can I compile a static library in and use it in other .cpp code. I have header.cpp,…
linuxx
  • 1,487
  • 4
  • 16
  • 17
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
127
votes
4 answers

error: unknown type name ‘bool’

I downloaded the source code and wanted to compile the file of scanner. It produces this error: [meepo@localhost cs143-pp1]$ gcc -o lex.yy.o lex.yy.c -ll In file included from scanner.l:15:0: scanner.h:59:5: error: unknown type name ‘bool’ In file…
Meepo
  • 1,291
  • 2
  • 8
  • 6
127
votes
13 answers

How can I use "sizeof" in a preprocessor macro?

Is there any way to use a sizeof in a preprocessor macro? For example, there have been a ton of situations over the years in which I wanted to do something like: #if sizeof(someThing) != PAGE_SIZE #error Data structure doesn't match page…
Brad
  • 11,262
  • 8
  • 55
  • 74
127
votes
15 answers

Unmangling the result of std::type_info::name

I'm currently working on some logging code that supposed to - among other things - print information about the calling function. This should be relatively easy, standard C++ has a type_info class. This contains the name of the typeid'd…
terminus
  • 13,745
  • 8
  • 34
  • 37
126
votes
8 answers

Is there a compiler hint for GCC to force branch prediction to always go a certain way?

For the Intel architectures, is there a way to instruct the GCC compiler to generate code that always forces branch prediction a particular way in my code? Does the Intel hardware even support this? What about other compilers or hardwares? I would…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295