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
202
votes
5 answers

Is gcc's __attribute__((packed)) / #pragma pack unsafe?

In C, the compiler will lay out members of a struct in the order in which they're declared, with possible padding bytes inserted between members, or after the last member, to ensure that each member is aligned properly. gcc provides a language…
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
200
votes
6 answers

How to print the ld(linker) search path

What is the way to print the search paths that in looked by ld in the order it searches.
Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
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
195
votes
3 answers

Warning/error "function declaration isn't a prototype"

I have a library I created, File mylib.c: #include int testlib() { printf("Hello, World!\n"); return (0); } File mylib.h: #include extern int testlib(); In my program, I've attempted to call this library function: File…
Alan H
  • 3,021
  • 4
  • 25
  • 24
193
votes
7 answers

What is the advantage of GCC's __builtin_expect in if else statements?

I came across a #define in which they use __builtin_expect. The documentation says: Built-in Function: long __builtin_expect (long exp, long c) You may use __builtin_expect to provide the compiler with branch prediction information. In general,…
RajSanpui
  • 11,556
  • 32
  • 79
  • 146
192
votes
13 answers

Error "gnu/stubs-32.h: No such file or directory" while compiling Nachos source code

I am trying to install Nachos on my laptop and I have Ubuntu 11.04 on the laptop. The code is in C and so to build it I assume I will need cross compiler. This is where my problem is. I downloaded the source code of the MIPS cross compiler using…
Ashish Agarwal
  • 14,555
  • 31
  • 86
  • 125
191
votes
16 answers

Can't compile C program on a Mac after upgrade to Mojave

I have used the gcc command on the terminal to compile C programs but all of a sudden, after an update to my Mac's OS (to macOS 10.14 Mojave, and XCode 10.0), I started receiving the message: test.c:8:10: fatal error: stdio.h: No such file or…
Maxxx
  • 3,688
  • 6
  • 28
  • 55
190
votes
3 answers

Why does GCC generate such radically different assembly for nearly the same C code?

While writing an optimized ftol function I found some very odd behaviour in GCC 4.6.1. Let me show you the code first (for clarity I marked the differences): fast_trunc_one, C: int fast_trunc_one(int i) { int mantissa, exponent, sign, r; …
orlp
  • 112,504
  • 36
  • 218
  • 315
189
votes
6 answers

Clang vs GCC for my Linux Development project

I'm in college, and for a project we're using C. We've explored GCC and Clang, and Clang appears to be much more user friendly than GCC. As a result, I'm wondering what the advantages or disadvantages are to using clang, as opposed to GCC, for…
haziz
  • 12,994
  • 16
  • 54
  • 75
189
votes
5 answers

What are the GCC default include directories?

When I compile a very simple source file with gcc I don't have to specify the path to standard include files such as stdio or stdlib. How does GCC know how to find these files? Does it have the /usr/include path hardwired inside, or it will get the…
Raxvan
  • 6,257
  • 2
  • 25
  • 46
188
votes
2 answers

Telling gcc directly to link a library statically

It feels strange to me to use -Wl,-Bstatic in order to tell gcc which libraries I want to link with statically. After all I'm telling gcc directly all other information about linking with libraries (-Ldir, -llibname). Is it possible to tell the gcc…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
188
votes
7 answers

How can I link to a specific glibc version?

When I compile something on my Ubuntu Lucid 10.04 PC it gets linked against glibc. Lucid uses 2.11 of glibc. When I run this binary on another PC with an older glibc, the command fails saying there's no glibc 2.11... As far as I know glibc uses…
falstaff
  • 3,413
  • 2
  • 25
  • 26
187
votes
11 answers

Why does flowing off the end of a non-void function without returning a value not produce a compiler error?

Ever since I realized many years ago, that this doesn't produce an error by default (in GCC at least), I've always wondered why? I understand that you can issue compiler flags to produce a warning, but shouldn't it always be an error? Why does it…
Catskul
  • 17,916
  • 15
  • 84
  • 113
185
votes
3 answers

How to compile a static library in Linux?

I have a question: How to compile a static library in Linux with gcc, i.e. I need to compile my source code into a file named out.a. Is it sufficient to simply compile with the command gcc -o out.a out.c? I'm not quite familiar with gcc, hope anyone…
Summer_More_More_Tea
  • 12,740
  • 12
  • 51
  • 83
180
votes
9 answers

ld cannot find an existing library

I am attempting to link an application with g++ on this Debian lenny system. ld is complaining it cannot find specified libraries. The specific example here is ImageMagick, but I am having similar problems with a few other libraries too. I am…
maxpenguin
  • 5,039
  • 6
  • 28
  • 22