All Questions
13,400
questions
1630
votes
23
answers
380k
views
Compiling an application for use in highly radioactive environments
We are compiling an embedded C++ application that is deployed in a shielded device in an environment bombarded with ionizing radiation. We are using GCC and cross-compiling for ARM. When deployed, our ...
1172
votes
11
answers
640k
views
What is the difference between g++ and gcc?
What is the difference between g++ and gcc? Which one of them should be used for general c++ development?
799
votes
2
answers
99k
views
Why is my program slow when looping over exactly 8192 elements?
Here is the extract from the program in question. The matrix img[][] has the size SIZE×SIZE, and is initialized at:
img[j][i] = 2 * j + i
Then, you make a matrix res[][], and each field in here is ...
694
votes
31
answers
503k
views
How to automatically generate a stacktrace when my program crashes
I am working on Linux with the GCC compiler. When my C++ program crashes I would like it to automatically generate a stacktrace.
My program is being run by many different users and it also runs on ...
618
votes
11
answers
571k
views
How do I list the symbols in a .so file
How do I list the symbols being exported from a .so file? If possible, I'd also like to know their source (e.g. if they are pulled in from a static library).
I'm using gcc 4.0.2, if that makes a ...
590
votes
14
answers
2.7m
views
Convert char to int in C and C++
How do I convert a char to an int in C and C++?
590
votes
5
answers
393k
views
GCC -fPIC option
I have read about GCC's Options for Code Generation Conventions, but could not understand what "Generate position-independent code (PIC)" does. Please give an example to explain me what does it mean.
581
votes
6
answers
760k
views
Debug vs Release in CMake
In a GCC compiled project,
How do I run CMake for each target type (debug/release)?
How do I specify debug and release C/C++ flags using CMake?
How do I express that the main executable will be ...
551
votes
21
answers
879k
views
Undefined reference to vtable
When building my C++ program, I'm getting the error message
undefined reference to 'vtable...
What is the cause of this problem? How do I fix it?
It so happens that I'm getting the error for the ...
532
votes
17
answers
527k
views
How do you get assembler output from C/C++ source in GCC?
How does one do this?
If I want to analyze how something is getting compiled, how would I get the emitted assembly code?
515
votes
6
answers
123k
views
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 ...
445
votes
5
answers
190k
views
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 ...
429
votes
23
answers
464k
views
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 ...
342
votes
6
answers
404k
views
Error "undefined reference to 'std::cout'"
Shall this be the example:
#include <iostream>
using namespace std;
int main()
{
cout << "Hola, moondo.\n";
}
It throws the error:
gcc -c main.cpp gcc -o edit main.o main....
328
votes
23
answers
333k
views
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 ...
328
votes
8
answers
385k
views
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 ...
299
votes
4
answers
88k
views
What is the order of evaluation in a member initializer list?
I have a constructor that takes some arguments. I had assumed that they were initialized in the order listed, but in one case, it appears they were being initialized in reverse, resulting in an abort. ...
259
votes
8
answers
107k
views
How can I turn on (literally) ALL of GCC's warnings?
I would like to enable—literally—all of the warnings that GCC has. (You'd think it would be easy...)
You'd think -Wall might do the trick, but nope! You still need -Wextra.
You'd think -Wextra might ...
240
votes
1
answer
7k
views
std::vector performance regression when enabling C++11
I have found an interesting performance regression in a small C++ snippet, when I enable C++11:
#include <vector>
struct Item
{
int a;
int b;
};
int main()
{
const std::size_t num_items ...
225
votes
10
answers
163k
views
Where does gcc look for C and C++ header files?
On a Unix system, where does gcc look for header files?
I spent a little time this morning looking for some system header files, so I thought this would be good information to have here.
196
votes
5
answers
148k
views
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/...
190
votes
6
answers
119k
views
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 ...
188
votes
11
answers
91k
views
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, ...
182
votes
23
answers
592k
views
CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
I'm trying make a Visual Studio solution with CMake to compile the latest version of aseprite and CMake keeps giving me the:
No CMAKE_C_COMPILER could be found.
No CMAKE_CXX_COMPILER could be found.
...
179
votes
7
answers
308k
views
How to compile for Windows on Linux with gcc/g++?
I have written some effects in C++ (g++) using freeglut on Linux, and I compile them with
g++ -Wall -lglut part8.cpp -o part8
So I was wondering if it is possible to have g++ make static compiled ...
178
votes
8
answers
177k
views
What is the purpose of using -pedantic in the GCC/G++ compiler?
This note says:
-ansi: tells the compiler to implement the ANSI language option. This turns
off certain "features" of GCC which
are incompatible with the ANSI
standard.
-pedantic: used in ...
173
votes
3
answers
126k
views
Difference between CC, gcc and g++?
What are the difference between the 3 compilers CC, gcc, g++ when compiling
C and C++ code in terms of assembly
code generation, available libraries, language features, etc.?
172
votes
4
answers
10k
views
An expensive jump with GCC 5.4.0
I had a function which looked like this (showing only the important part):
double CompareShifted(const std::vector<uint16_t>& l, const std::vector<uint16_t> &curr, int shift, int ...
172
votes
7
answers
364k
views
error: use of deleted function
I've been working on some C++ code that a friend has written and I get the following error that I have never seen before when compiling with gcc4.6:
error: use of deleted function
‘GameFSM_<std::...
171
votes
3
answers
319k
views
How does #include <bits/stdc++.h> work in C++? [duplicate]
I have read from a codeforces blog that if we add #include <bits/stdc++.h> in a C++ program then there is no need to include any other header files. How does #include <bits/stdc++.h> work ...
168
votes
5
answers
90k
views
Why does this loop produce "warning: iteration 3u invokes undefined behavior" and output more than 4 lines?
Compiling this:
#include <iostream>
int main()
{
for (int i = 0; i < 4; ++i)
std::cout << i*1000000000 << std::endl;
}
and gcc produces the following warning:
...
167
votes
1
answer
86k
views
What are the differences between -std=c++11 and -std=gnu++11?
What are the differences between -std=c++11 and -std=gnu++11 as compilation parameter for gcc and clang? Same question with c99 and gnu99? I know about C++ and C standards, it's the differences in the ...
161
votes
11
answers
245k
views
Compile error: "g++: error trying to exec 'cc1plus': execvp: No such file or directory"
When I compile C/C++ program with popen in php... I got this error:
g++: error trying to exec 'cc1plus': execvp: No such file or directory
but if I run php code in shell.. it works fine..
in Arch ...
158
votes
13
answers
160k
views
How to remove unused C/C++ symbols with GCC and ld?
I need to optimize the size of my executable severely (ARM development) and
I noticed that in my current build scheme (gcc + ld) unused symbols are not getting stripped.
The usage of the arm-strip --...
156
votes
7
answers
255k
views
What does the fpermissive flag do?
I'm just wondering what the -fpermissive flag does in the g++ compiler? I am getting:
error: taking address of temporary [-fpermissive]
which I can solve by giving the -fpermissive flag to the ...
152
votes
3
answers
37k
views
LLVM vs clang on OS X
I have a question concerning llvm, clang, and gcc on OS X.
What is the difference between the llvm-gcc 4.2, llvm 2.0 and clang? I know that they all build on llvm but how are they different?
...
151
votes
5
answers
124k
views
Explicit specialization in non-namespace scope [duplicate]
template<typename T>
class CConstraint
{
public:
CConstraint()
{
}
virtual ~CConstraint()
{
}
template <typename TL>
void Verify(int position, int ...
150
votes
5
answers
10k
views
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....
143
votes
19
answers
331k
views
/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 get:
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
...
140
votes
6
answers
17k
views
Why does integer overflow on x86 with GCC cause an infinite loop?
The following code goes into an infinite loop on GCC:
#include <iostream>
using namespace std;
int main(){
int i = 0x10000000;
int c = 0;
do{
c++;
i += i;
...
140
votes
3
answers
82k
views
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?
138
votes
6
answers
77k
views
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 <foo.h>
g++ will scan the search path, using any include options to add or alter the path. But, at the end ...
138
votes
4
answers
106k
views
Downcasting shared_ptr<Base> to shared_ptr<Derived>?
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 ...
132
votes
16
answers
61k
views
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. ...
131
votes
10
answers
280k
views
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/...
131
votes
8
answers
191k
views
error: ‘NULL’ was not declared in this scope [closed]
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.
130
votes
3
answers
177k
views
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 ...
129
votes
8
answers
33k
views
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? ...
128
votes
6
answers
103k
views
experimental::filesystem linker error
I try to use the new c++1z features actually on the head of development within gcc 6.0.
If I try this little example:
#include <iostream>
#include <experimental/filesystem>
namespace fs =...
125
votes
1
answer
52k
views
Member initialization while using delegated constructor
I've started trying out the C++11 standard and i found this question which describes how to call your ctor from another ctor in the same class to avoid having a init method or the like. Now i'm trying ...