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

How to count clock cycles with RDTSC in GCC x86?

With Visual Studio I can read the clock cycle count from the processor as shown below. How do I do the same thing with GCC? #ifdef _MSC_VER // Compiler: Microsoft Visual Studio #ifdef _M_IX86 // Processor: x86 …
Johan Råde
  • 20,480
  • 21
  • 73
  • 110
20
votes
8 answers

Does GCC have a built-in compile time assert?

Our existing compile-time assert implementation is based on negative array index, and it provides poor diagnostic output on GCC. C++0x's static_assert is a very nice feature, and the diagnostic output it provides is much better. I know GCC has…
VladLosev
  • 7,296
  • 2
  • 35
  • 46
20
votes
2 answers

unique_ptr compile error

I guess this is embarrassing if I told you I cant get this to compile. would you please help me: #include using namespace std; int main() { std::unique_ptr p1(new int(5)); return 0; } $ gcc main.cpp main.cpp: In function…
rahman
  • 4,820
  • 16
  • 52
  • 86
20
votes
5 answers

Optimization levels in gcc changing c program behaviour

I'm seeing behaviour I don't expect when compiling this code with different optimization levels in gcc. The function test should fill a 64 bit unsigned integer with ones, shift them shift_size bits to the left, and return the 32 low bits as a 32 bit…
user1142769
  • 201
  • 1
  • 4
20
votes
7 answers

enum type check in C/gcc

See the simple example below. When a function returning one enum is assigned to a variable of a different enum I don't get any warning even with gcc -Wall -pedantic. Why is it not possible for a C compiler to do type checking on enums? Or is it gcc…
Manohar
  • 3,865
  • 11
  • 41
  • 56
20
votes
1 answer

What is the exact equivalent to LD_PRELOAD on OSX?

I am using LD_PRELOAD to hook a library function, and in Linux it works perfectly. But I cannot figure out how to do the equivalent in OSX. The setup I have on Linux is as follows: The code is: #include #include #include…
horseyguy
  • 29,455
  • 20
  • 103
  • 145
20
votes
5 answers

How to compile C program without any optimization

How can I compile a C program without undergoing any optimizations using gcc/g++?
Sarath Babu
  • 923
  • 3
  • 10
  • 27
20
votes
1 answer

Why am I getting a gcc "undefined reference" error trying to create shared objects?

Why am I getting an "undefined reference" error using gcc? I am trying to create a shared object (.so) that exports one function, "external()". I then try to link against the .so but get "undefined reference 'external'". What am I doing wrong…
Warren
  • 1,903
  • 1
  • 21
  • 30
20
votes
8 answers

Set last `n` bits in unsigned int

How to set (in most elegant way) exactly n least significant bits of uint32_t? That is to write a function void setbits(uint32_t *x, int n);. Function should handle each n from 0 to 32. Especially value n==32 should be handled.
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
20
votes
3 answers

Are there known false positives issues with Valgrind?

Are there any known false positives with Valgrind? I get a 'Conditional jump or move depends on uninitialised value(s)' with the fmemopen function, writing in C and compiling with GCC. Can I be sure it's real? EDIT: Are there known issues that are…
Liran Orevi
  • 4,755
  • 7
  • 47
  • 64
20
votes
4 answers

Mac Rmagick won't install with Xcode 4.2

I just got a new macbook pro and trying to setup my dev environment. I downloaded xcode 4.2 from the app store and installed it, after this i installed homebrew and RVM. ImageMagick, readline, ruby 1.9.3-head all installed perfectly until i ran…
Danny Hiemstra
  • 1,188
  • 1
  • 9
  • 13
20
votes
4 answers

How can one provide custom compiler/linker flags for OpenSSL?

I'm trying to build OpenSSL with -Wa,--noexecstack, but can't find anywhere in its config command-line to provide this flag. I've tried to set CFLAGS, but it appears to ignore that and just use its own. This is an automated build working off a…
DNS
  • 37,249
  • 18
  • 95
  • 132
20
votes
2 answers

Linking libraries with gcc: order of arguments

As soon as I upgraded my Ubuntu distro to 11.10, I started seeing strange linker behavior with gcc. I was able to fix the problem by moving my -l arguments to the end of the gcc command (my problem was similar to the one described in this thread,…
Daniel Standage
  • 8,136
  • 19
  • 69
  • 116
20
votes
4 answers

Changing compiler in Qt

How to change compiler (GCC) in Qt? I've installed GCC 4.4 and 4.6. At the momment Qt uses 4.4 but I'd like it to use 4.6. How to do it?
smallB
  • 16,662
  • 33
  • 107
  • 151
20
votes
3 answers

Recursion without recursive call?

Found this on /prog/. I actually GDB'd it, and yes, it was truly a recursion. But how did it happen? // This works on 32-bit x86 Linux with gcc as long as you don't enable optimization. #include #include static void…
user769143
  • 219
  • 1
  • 4