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
509
votes
6 answers

Why does GCC generate 15-20% faster code if I optimize for size instead of speed?

I first noticed in 2009 that GCC (at least on my projects and on my machines) have the tendency to generate noticeably faster code if I optimize for size (-Os) instead of speed (-O2 or -O3), and I have been wondering ever since why. I have managed…
Ali
  • 56,466
  • 29
  • 168
  • 265
494
votes
11 answers

"Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo." when using GCC

While attempting to compile my C program, running the following command: gcc pthread.c -o pthread Returns: Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo. and my code does not compile. Why is this…
coachcal
  • 12,841
  • 3
  • 16
  • 12
492
votes
38 answers

setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

When I try to install odoo-server, I got the following error: error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 Could anyone help me to solve this issue?
Madura Dissanayake
  • 8,309
  • 5
  • 25
  • 34
474
votes
22 answers

gcc makefile error: "No rule to make target ..."

I'm trying to use GCC (linux) with a makefile to compile my project. I get the following error which is can't seem to decipher in this context: "No rule to make target 'vertex.cpp', needed by 'vertex.o'. Stop." This is the makefile: a.out:…
Meir
  • 12,285
  • 19
  • 58
  • 70
446
votes
10 answers

How do the likely/unlikely macros in the Linux kernel work and what is their benefit?

I've been digging through some parts of the Linux kernel, and found calls like this: if (unlikely(fd < 0)) { /* Do something */ } or if (likely(!err)) { /* Do something */ } I've found the definition of them: #define likely(x) …
terminus
  • 13,745
  • 8
  • 34
  • 37
433
votes
5 answers

How exactly does __attribute__((constructor)) work?

It seems pretty clear that it is supposed to set things up. When exactly does it run? Why are there two parentheses? Is __attribute__ a function? A macro? Syntax? Does this work in C? C++? Does the function it works with need to be static? When…
Casebash
  • 114,675
  • 90
  • 247
  • 350
427
votes
23 answers

How to get rid of `deprecated conversion from string constant to ‘char*’` warnings in GCC

I'm working on an exceedingly large codebase, and recently upgraded to GCC 4.3, which now triggers this warning: warning: deprecated conversion from string constant to ‘char*’ Obviously, the correct way to fix this is to find every declaration…
Josh Matthews
  • 12,816
  • 7
  • 36
  • 39
388
votes
8 answers

How do I force make/GCC to show me the commands?

I'm trying to debug a compilation problem, but I cannot seem to get GCC (or maybe it is make??) to show me the actual compiler and linker commands it is executing. Here is the output I am seeing: CCLD …
hernejj
  • 3,889
  • 2
  • 15
  • 3
349
votes
4 answers

How can I add a default include path for GCC in Linux?

I'd like GCC to include files from $HOME/include in addition to the usual include directories, but there doesn't seem to be an analogue to $LD_LIBRARY_PATH. I know I can just add the include directory at command line when compiling (or in the…
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
345
votes
15 answers

Removing trailing newline character from fgets() input

I am trying to get some data from the user and send it to another function in gcc. The code is something like this. printf("Enter your Name: "); if (!(fgets(Name, sizeof Name, stdin) != NULL)) { fprintf(stderr, "Error reading Name.\n"); …
sfactor
  • 12,592
  • 32
  • 102
  • 152
327
votes
4 answers

This C function should always return false, but it doesn’t

I stumbled over an interesting question in a forum a long time ago and I want to know the answer. Consider the following C function: f1.c #include bool f1() { int var1 = 1000; int var2 = 2000; int var3 = var1 + var2; …
Dimitri Podborski
  • 3,714
  • 3
  • 19
  • 31
325
votes
6 answers

Error "undefined reference to 'std::cout'"

Shall this be the example: #include using namespace std; int main() { cout << "Hola, moondo.\n"; } It throws the error: gcc -c main.cpp gcc -o edit main.o main.o: In function `main': main.cpp:(.text+0xa): undefined reference to…
D1X
  • 5,025
  • 5
  • 21
  • 36
319
votes
23 answers

How do I best silence a warning about unused variables?

I have a cross platform application and in a few of my functions not all the values passed to functions are utilised. Hence I get a warning from GCC telling me that there are unused variables. What would be the best way of coding around the…
Phil Hannent
  • 12,047
  • 17
  • 71
  • 118
316
votes
8 answers

Inheriting constructors

Why does this code: class A { public: explicit A(int x) {} }; class B: public A { }; int main(void) { B *b = new B(5); delete b; } Result in these errors: main.cpp: In function ‘int main()’: main.cpp:13: error: no matching…
Sydius
  • 13,567
  • 17
  • 59
  • 76
315
votes
11 answers

Using GCC to produce readable assembly?

I was wondering how to use GCC on my C source file to dump a mnemonic version of the machine code so I could see what my code was being compiled into. You can do this with Java but I haven't been able to find a way with GCC. I am trying to re-write…
James
  • 3,682
  • 3
  • 22
  • 21