FAQ Database Discussion Community


fatal error: limits.h: No such file or directory

xcode,osx,gcc
On OSX, I can't compile simple programs from the command-line when I use an externally-provided compiler (e.g. gcc-4.8). System headers like limits.h cannot be found. Example error messages: fatal error: limits.h: No such file or directory Or: fatal error: stdio.h: No such file or directory and so on. What's wrong?...

Native Code: cannot use typeid with -fno-rtti

c++,osx,gcc,android-ndk,vtk
I'm trying to build native code on android because I want to use VTK for my android tablet. However, I am facing some issues when it comes to building one of the vtk examples. I know this problem has been covered here for an objective c issue but I guess...

Using local brew formula to install cross platform gcc compiler

gcc,homebrew
I need to install gcc cross compiler that generates ELF, and I found this site - http://time.to.pullthepl.ug/blog/2014/2/3/xv6-on-mac-os-x/ It points to a github for home-brew-gcc_cross_compilers (https://github.com/jinmel/homebrew-gcc_cross_compilers), and put them in homebrew formulas, but I'm not sure exactly how to put them in the formula. Then, how to download the github code...

How can I use GoogleMock in jenkins?

c++,gcc,jenkins,centos,googlemock
I installed Jenkins on a CentOS vm. Now I want to run unittests (google test) with mocks (google mock). I tried installing the frameworks like described here. (On my lubuntu machine everything runs without a problem using these steps) When I try to build: g++ -O2 -pthread -Werror -Wall -o...

Why it is allowed to initialize static variable with non const here?

c,gcc,initialization,const,static-variables
I was reading this. The first answer by @Andrei T says that A "large" object is never a constant expression in C, even if the object is declared as const. Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects...

Checking all elements of array for a logical condition in fortran

gcc,fortran,gfortran
I want to check all rows of an array for a logical condition. I used function ALL as described in GNU GCC guide https://gcc.gnu.org/onlinedocs/gfortran/ALL.html Here is a sample code: program test3 implicit none real, allocatable, dimension (:,:) :: mat1 integer :: i,j,k,r logical :: lg r=3 allocate(mat1(r,r)) mat1=transpose( reshape( (/-1,-2,-3,-4,-5,-6,-7,-8,-9/),...

(solaris) ld: fatal: … version 'GCC_4.2.0' does not exist

c++,gcc,linker
I'm trying to compile a c++ program for the first time on this machine (which is not mine), so I've written a simple hello world. My command to compile gets an error, >g++ testing.cpp -L/usr/local/lib ld: fatal: file /usr/local/lib/libgcc_s.so: version 'GCC_4.2.0' does not exist: required by file /usr/local/lib/libstdc++.so but I...

nvcc/CUDA 6.5 & c++11(future) - gcc 4.4.7

c++11,gcc,cuda,future
When I compile the following code containing the design C++11, I get errors - it does not compile. I've tried with different flags, but I haven't found a solution. My setting: CUDA 6.5, gcc 4.4.7 I am not able to change the settings. How can I still make this work?...

ARM assembly cannot use immediate values and ADDS/ADCS together

gcc,assembly,arm,instructions
I am currently trying to speed up some of my C functions on a Cortex-M0 (Freescale KL25Z) using assembly. I get a problem with this minimal test program: @.syntax unified .cpu cortex-m0 .text .global test .code 16 test: mov r0, #0 adds r0, r0, #1 bx lr When I try...

scanf issue when reading double

c,gcc,double,user-input,scanf
I'm using MinGW on windows 7 to compile C files. My problem is a strange behaviour with scanf() to read doubles from user input. My code: int main() { double radius = 0; double pi = 3.14159; scanf("%lf \n", &radius); // after the input, it continues waiting... radius = ((radius...

When can/will a function be inlined in C++? Can inline behavior be forced?

c++,gcc,clang,compiler-optimization
I am trying to get the expected behavior when I use the keyword inline. I tried calling a function in different files, templating the function, using different implementation of the inline function, but whatever I do, the compiler is never inlining the function. So in which case exactly will the...

There is a way in gcc to get a warning when a constexpr can't be evaluated at compile time?

gcc,g++,c++14,constexpr
I'm using gcc 5.1.0 (c++14) and I was trying with constexpr. Is very annoying to verify if the constexpr I've implemented are evaluated at compile time. I couldn't find any flag for get a warning about that situation. Here is an example: example.cpp ----------------------------------------- #include <stdlib.h> const char pruVar[] =...

How to have gcc warn about conversions from uint32_t to uint64_t?

c++,gcc,compiler-warnings
Let's take the following simple example: #include <vector> #include <cstdint> using ::std::vector; using ::std::uint64_t; using ::std::uint32_t; int main(int argc, char *argv[]) { vector<uint64_t> v; uint32_t i = 1; v.push_back(i); return 0; } When I compile it with: g++ -std=c++11 -Wall -Wconversion -Wpedantic a.cpp I don't get any conversion error. However,...

Django MySQLClient pip compile failure on Linux

python,linux,django,gcc,pip
Django documentation as of v1.8 recommends using mysqlclient connector for the framework. I'm attempting to pip install the package on Ubuntu 14.04 with Python 3.4 and running into a GCC error that I'm unable to find reference to. I'm not an expert on compiling software, so was hoping somebody can...

different clang and gcc behavior with pointers

c++,c,gcc,clang
For example, we have the following simple code: #include "stdio.h" int main() { int* pointer_to_check; printf("%x\n", pointer_to_check); return 0; } With gcc, we will get zero at output (as for me, normal behavior, because pointer isn't associated with memory), but clang gives us a real address, which can be accessed...

c++ segfault on one platform (MacOSX) but not another (linux)

c++,linux,osx,gcc,llvm
I'm getting a segfault on MacOSX ("Segmentation fault: 11", in gdb "Program received signal SIGSEGV, Segmentation fault"), appearing in the destructor in which a container is looped over with an iterator and memory deleted. I've tried with clang++, g++ (both part of LLVM) and homebrew g++. The segfault appears when...

GCC on Solaris - parse error before `0x00000002'

c++,gcc,solaris
I'm working on a C++ project that is compiled on a few platforms, including Windows, Linux, and Solaris. The Solaris version of the code is quite old. I'm updating it with changes made over several years, and getting weird compiler errors with code that compiles fine on Windows and Linux....

Is sse2 enabled by default in g++?

c++,linux,gcc
When I run g++ -Q --help=target, I get -msse2 [disabled]. However, if I create the assembly code of with default options as g++ -g mycode.cpp -o mycode.o; objdump -S mycode.o > default, and a sse2 version with g++ -g -msse2 mycode.cpp -o mycode.sse2.o; objdump -S mycode.sse2.o > sse2, and finally...

How to uglify or minify C code [closed]

c,gcc,minify
Using gcc I can remove comments and unwanted blank lines, but I want to reduce a size of file also, is there any options in gcc or any other tool to do so At present I do like this gcc -fpreprocessed -dD -E -P source_code.c > source_code_comments_removed.c Here is scenario...

Print addresses of all local variables in C

debugging,pointers,gcc,gdb,memory-address
I want to print the addresses of all the local and global variables which are being used in a function, at different points of execution of a program and store them in a file. I am trying to use gdb for this same. The "info local" command prints the values...

Linux VM with custom architecture

linux,gcc,glibc,qemu
I'm looking into creating a couple of VMs (probably but not necessarily using QEMU) with different parameters/architecture. Different sizeof(int) Different endiannes Different alignment rules (e.g. int must be aligned on 4-byte boundary) etc... I'm familiar with building my own kernel, gcc, glibc etc but I'm not entirely sure what actually...

MinGW's ld cannot perform PE operations on non PE output file

gcc,assembly,mingw,nasm,osdev
I know there are some other similar questions about this out there, be it StackOverflow or not. I've researched a lot for this, and still didn't find a single solution. I'm doing an operative system as a side project. I've been doing all in Assembly, but now I wanna join...

Unexpected performance with global variables

c,pointers,gcc,global-variables
I am getting a strange result using global variables. This question was inspired by another question. In the code below if I change int ncols = 4096; to static int ncols = 4096; or const int ncols = 4096; the code runs much faster and the assembly is much simpler....

gcc links to wrong GLIBCXX version when O2 flag is specified

c++,linux,gcc,linker,ld
I have a shared library file which I build using a Makefile. I ran into an issue where, after building the library, I'd get the dreaded GLIBCXX_ not found linker error. This case is particularly strange. When I compile with the -g3 flag, I don't get the error. If I...

Inter-dependencies between static libraries

eclipse,gcc,linker,dependencies,static-libraries
I am trying to link two libraries libA.a and libB.a along with a main.c file. libB has dependencies on libA, and main has dependencies on both. I am able to compile the libraries independently, but when I try to link them together to create the final executable, I get the...

error: cannot convert 'bool' to 'svLogic*' in assignment

c++,gcc,system-verilog,dpi,modelsim
We are working on the system verilog DPI calls. While compiling the C++ file we are getting the errors like this: error: cannot convert 'bool' to 'svLogic*' in assignment Here svLogic is 4-state variable. The VCS simulator has predefined function in DirectC method vc_putScalar, where vc_putScalar is "Passes the value...

Usage of #ifndef directive

c,gcc
I'm trying to use #ifndef as below. #ifndef MACRO1 || #ifndef MACRO2 .... #endif I already tried: #ifndef (MACRO1 || MACRO2) .. #endif But for both cases am getting below error error: extra tokens at end of #ifndef directive ...

Does gcc search CPATH recursively?

gcc,include
On a Linux system, does gcc recursively search the path declared in CPATH environment variable, or do I need to specify every Includes sub-directory explicitly?

Different behavior of async with Visual Studio 2013(Windows8.1) and GCC 4.9(Ubuntu14.10)

c++,linux,multithreading,c++11,gcc
async has different behavior(implementation) in Windows VS and Linux g++. I tested it with the following code: void Func1(){sleep(1000*1000);} void Func2(){sleep(1000*2);throw runtime_error("An expected exception");} int main(int argc, char* argv[]){ try{ auto f1 = async(launch::async, Func1); auto f2 = async(launch::async, Func2); f2.get();//block here f1.get(); }catch (exception& e){ printf("exception: %s\n", e.what()); }...

Installing libraries for arm-gcc-compiler

linux,gcc,arm,cross-compiling,embedded-linux
I have a functional arm cross compiler that I can use with arm-linux-gnueabi-gcc command. This works for simple programs but I run into problems when I have to compile bigger programs requiring libraries like x11, opengl as the required headers/files are not present in arm-linux-gnuebi directory but in normal gcc...

gcc auto dependency full path

c++,gcc,makefile,g++
I have a simple project - it has a foo.cxx and a bar.h: // bar.h // nothing // foo.cxx #include "bar.h" // nothing else If I include bar.h with ""s, then the dependency file has everything with its full paths: $ g++ -std=c++11 -MP -MMD -MF /home/barry/sandbox/foo.d -c /home/barry/sandbox/foo.cxx -o...

Text as parameter in inline assembly (ARM)?

gcc,arm,inline-assembly
Is there a way to put plain text in inline assembly (ARM)? My problem is reading banked registers. The syntax is (r11 of user mode): mrs r0, r11_usr The problem is the "usr"-part. I tried: #define READ_REG_MODE(retvar, rg, mode) \ asm volatile (\ "mrs %[reg], r%c[rn]_%c[mod]\n\t"\ :[reg] "=r" (retvar)\ :[rn]"I"(rg),...

Why should I use a closing bracket in this? [closed]

c++,gcc
I have some code which I could not compile it yet. The compiler says there should be a closing bracket, but I can't see a reason for this or place to put it. This is my code: #include "Player.h" Player(std::string val){ set_Name(val); set_Alliance("NONE"); set_LastUpdate(); } Player(std::string val, std::string ally){ set_Name(val);...

C++ - stoi() was not declared in this scope

c++,c++11,gcc,compiler-errors,codeblocks
I'm practicing my C++ by coding simple input/ouput from user. I have now been searching for over an hour on how to convert a string to an int. Every answer is different, and require something else. I'm using Code::Blocks v.13.12. MingW32 folder is added to environment variables. I ended up...

Installing Statnet

r,osx,gcc,statnet
Installing statnet on mac 10.10.3 with R 0.99.441. ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2' ld: library not found for -lgfortran clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [latentnet.so] Error 1 ERROR: compilation failed for package ‘latentnet’ * removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/latentnet’...

Printing Int variable in Float format [duplicate]

c,gcc,int,printf,format-specifiers
This question already has an answer here: What is printf's behaviour when printing an int as float? 3 answers I'm using gcc to compile this: int a=1; printf("%d\n",a); printf("%f\n",a); printf("%f\n",(float)a); I get: 1 0.000000 1.000000 Why does the implicit conversion give a wrong output?...

Why printf is not printing garbage value?

c,gcc,default,undefined-behavior,garbage
#include<stdio.h> void foo(){ int i; printf("%d\n",i); //should print garbage value } void main(){ foo(); } foo should print garbage value of i. But instead it is printing zero. Why is that? I am using gcc version 4.9.2....

How to override C compiler aligning word-sized variable in struct to word boundary

c,gcc,struct,bit-packing
I have a structure specified as following Member 1, 16 bits Member 2, 32 bits Member 3, 32 bits which I shall be reading from a file. I want to read straight from the file into the struct. The problem is that the C compiler will align the variables m1,...

What are the benefits of compiling with -j1 instead of -jN

c++,c,gcc
Compiling with -jN will compile faster, because it's compiling several parts at the same time. But GCC docs say (I can't find the exact link though) that compiling with -j1 will produce a better optimized binary. Can you explain all the benefits of compiling with -j1? Can you even provide...

Constants in C: declaration separate from definition

c,gcc,constants
All C code: Why is this allowed: int main() { const int *i; int j=2; i=&j; } But not this: int main() { const int i; int j=2; i=j; } Is there a way to declare a local constant variable and then define it elsewhere within the scope? The first...

FASM: Calling Tangent from GCC

gcc,assembly,fasm
I don't know what the problem is because this works perfectly for SIN and COS. For TAN, it returns 0.0000 for 50.0 radian. But if I enabled the commented line, it works as expected. That's weird because TAN is supposed to return a double in XMM0, not RAX. ;./fasm testing.asm...

Adding Armadillo to Qt project [SOLVED]

c++,qt,gcc,linker,armadillo
I am trying to run a test for the Armadillo library (5.2) which I have downloaded and I have uncommented the lines ARMA_USE_LAPACK and ARMA_USE_BLAS in the config.hpp file as recommended for Windows here . I have set the .pro file as such QT += core QT -= gui TARGET...

Range of immediate values in ARMv8 A64 assembly

gcc,assembly,arm64
My understanding is that immediate parameters in ARMv8 A64 assembly can be 12 bits long. If that is the case, why does this line of assembly code: AND X12, X10, 0xFEF Produce this error (when compiled with gcc) Error: immediate out of range at operand 3 -- `AND X12, X10,...

How is shellcode generated from C? - With code example

python,c,gcc,assembly,shellcode
I started taking an online course regarding software security. In one of the sections, I was instructed to execute a hidden C function using a buffer overflow. I got to thinking: what would happen if I could pass machine instruction directly to a stack unsafe executable? What I have been...

How can I know that which version of gcc compiler I am using?

gcc,version
In java, there is command line option javac -version to know the version that is installed on computer. I am curious to know about is there any way exist to know the version of gcc or any command line option that can help me? Remember I am not asking about...

Can I have optimization on, but not suffer from reordered statements?

c,gcc
My debug CFLAGS were always -g -O0. The latter mainly to disable jumps to unexpected line while debugging. Nowadays more and more programs refuse to compile with -O0, besides, -D_FORTIFY_SOURCE require optimizer. is it possible to compile with -O, but have predictable behavior in debugger? ...

C - pthread_create - Clang GCC difference

c,gcc,pthreads,clang
Passing the argument to pthread_create with clang (3.6.1) and gcc (5.1.0) brings different results for a strange case, illustrated here: pthread_t spawn_bserver_thread(uint16_t portno) { pthread_t tid; int32_t sockfd = create_bserver(portno); set_nonblocking(sockfd); exit_ncurses(); printf("%d\n", sockfd); if(pthread_create(&tid, NULL, bserver_thread, &sockfd) != 0) error("pthread_create"); return tid; } and bserver_thread: static void * bserver_thread(void...

weird optimization (remove a function) in GCC

c,gcc,optimization
I met a weird optimization in GCC 4.8.2 with -O2, which removes a function. See the following code. increase() and increase2() are same except that there is a printf() in the latter one. However increase() is removed if using -O2 in GCC. #include <stdio.h> #include <stdint.h> #include <arpa/inet.h> void swap(uint64_t...

Failure to link a program with gcc -static

c,gcc
I'm trying to compile and link the following code with gcc: #include <stdlib.h> main() { exit(0); } I'm using gcc -static -o exit exit.c I get the following error: /usr/bin/ld: cannot find -lc collect2: ld returned 1 exit status What does this mean and how can I fix this? ...

Unclassifiable statement at (1) in Fortran

gcc,fortran,fortran90,gfortran
I am pretty new to to fortran and I don't really know why am I getting this error. integrand(i)=inte(x(i),beta,r2,r1) 1 Error: Unclassifiable statement at (1) calka11.f95:97.6: I have made all the variables into a module file and then call them using use and when I am getting those variables into...

How to mark function argument as output

c++,c,gcc,attributes,out
C# allows to mark function argument as output only: void func(out int i) { i = 44; } Is it possible to do something similar in C/C++? This could improve optimization. Additionally is should silence out warnings "error: 'myVar' may be used uninitialized in this function", when variable is not...

Can I use STDIN for IPC?

c,gcc,ipc,stdin
Can I use standard input for interprocess communication? I wrote the following gnu c code as an experiment, but the program hangs waiting for input after printing the character defined as val. Neither a newline nor fflush in the sending process seem to alleviate the problem. #include <unistd.h> #include <stdio.h>...

unrecognized debugging option: 1 [enabled by default]

c,gcc,compiler-errors,makefile,cross-platform
I am writing a cross-platform gtk application for Windows and linux in C. Today I came across the strange compiler error in the title (which I have never seen before). This happens when I build my program in Windows, but not in Linux. When I build it in Windows via...

Converting old C code

c,gcc,porting
I have this code snippet in project source code which I work on void func(void **p,size_t s) { *p = malloc(s+sizeof(size_t)); *(((size_t *)(*p))++) = s; } and gcc-4.7 does not compile it. gcc returns lvalue required as increment operand error message. I changed it into stp = ((size_t *)(*p)); *(stp...

How to set compiler-specific flags with autotools

gcc,clang,autotools,compiler-options
We use autotools as our build infrastructure, and we use clang and gcc as compilers. Recently we hit a gcc warning that needed --param max-vartrack-size=100000000 to silence (without completey disabling gcc's vartracking). Clang doesn't accept that option and produces argument unused during compilation: '--param max-vartrack-size=100000000' To silence that, clang needs...

How does using -L affect the linker?

linux,ubuntu,gcc,linker,ld
I'm rather new on Linux, so maybe this is a simple question. The question is: How does adding a -L/path affect the linker when there are no libraries attached? my issue: I'm trying to set up a cross-compilation toolchain featuring two pieces of third-party libraries¹. I'm using the linaro arm-linux-gnueabihf-raspbian...

Dereferencing pointer to incomplete type error for struct member access in Python swig C wrapper

python,c,gcc,compiler-errors,swig
What is the error while compiling swig Python wrapper under GCC 4.8.2? wfdb_python_wrap.c:3967:11: error: dereferencing pointer to incomplete type if (arg1->fname) free((char*)arg1->fname); ^ wfdb_python_wrap.c:3967:36: error: dereferencing pointer to incomplete type if (arg1->fname) free((char*)arg1->fname); source code from wfdb_python_wrap.c: ... #include <wfdb/wfdb.h> ... #ifdef __cplusplus extern "C" { #endif SWIGINTERN PyObject *_wrap_WFDB_Siginfo_fname_set(PyObject...

Does GCC merge files compiled together?

gcc,inline
Let's say that you have prog.c that includes lib.h, whose functions are defined in lib.c, and you build the program with ̀gcc -O3 lib.c prog.c. Does GCC merge both source files before compiling them? Is GCC able to inline short functions of lib.c into the resulting binary? Summary of answers...

How to check which symbols on my shared library have non-position independent code (PIC)?

linux,gcc,debian,powerpc
I'm trying to build a .deb package with debuild -i -us -uc -b and in the end I see: Now running lintian... warning: the authors of lintian do not recommend running it with root privileges! W: libluajit-5.1-2: hardening-no-relro usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0 E: libluajit-5.1-2: shlib-with-non-pic-code usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0 W: luajit: hardening-no-relro usr/bin/luajit-2.1.0-alpha W: luajit: binary-without-manpage...

Getting “format not a string literal and no format arguments” warning while using GTK+2

c,security,gcc,gtk,gcc-warning
I am getting an error like this: warning: format not a string literal and no format arguments [-Wformat-security] GTK_BUTTONS_OK, (const gchar*)message); ^ because of this function: static void show_message (gchar *message, GtkMessageType type) { GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, type, GTK_BUTTONS_OK, message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } How can I fix it?...

Trouble running C++ through terminal in Ubuntu

c++,linux,ubuntu,gcc,terminal
Hello Stack Community, My lack of reputation didn't allow me to post the picture of my problem. SO here it is in words- I wrote the following code after using "gedit take_input.cpp". #include <iostream> int main() { cout<<"please enter your name (followed by 'enter')\n"; string file; cin >> file; cout<<"hello"...

minigw-w64 is incapable of 32 byte stack alignment, easy work around or switch compilers?

c++,windows,gcc,alignment,sse
I'm trying to work with AVX instructions and windows 64bit. I'm comfortable with g++ compiler so I've been using that, however, there is a big bug described reported here and very rough solutions were presented here. Basically, m256 variable can't be aligned on the stack to work properly with avx...

GCC 5.1.0-4 cross compiler build fail

gcc,osdev
I'm following the osdev.org bare metal tutorial, and I'm currently stuck at the cross compiler.! I'm building from an arch distro. It looks like it might be a problem with isl. I think the tutorial is based on an older version of gcc, cloog, isl, etc, so after a few...

C++: List of tuples C++11/1y

c++,c++11,gcc
A previous question and answer (here) showed that a list of tuples could be created by: #include <vector> #include <boost/tuple/tuple.hpp> using namespace std; using boost::tuple; typedef vector< tuple<int, int> > tuple_list; While I don't get an error when running with C++98, C++1y (GCC/GNU on Ubuntu) gives: error: template argument 1...

Setting a float/double to a constant value in AT&T inline assembly

c++,c,gcc,assembly,inline
I'm looking at increasing the runtime performance of a C++ library that I have written and profiled. I'm very new to assembly (and inline assembly) and have a very basic question to ask. How do I set the value of an xmm register (xmm, ymm, zmm, etc) to a constant...

Interesting GCC Linking

c,pointers,gcc,linker,dynamic-linking
I was playing around with symbols and function pointers recently and noticed that though the following code runs fine: #include <stdio.h> int main(int argc, const char * argv[]) { printf("%p\n",printf); // <--this line makes it work int (*printfptr)(const char * restrict, ...); printfptr = 0x1001fe910; (*printfptr)("Hello world\n"); return 0; }...

Cross compiling for Raspberry pi 2 error

c,gcc,raspberry-pi,cross-compiling,raspberry-pi2
I wanted to start cross compiling for raspberry pi2 on Ubuntu 32bit (in virtual box), so I downloaded the toolchain on the github site (https://github.com/raspberrypi/tools) and tried to compile a simple hello world program with the command (I've included the path to the bin folder that contains arm-linux-gnueabihf-gcc-4.8.3 to the...

How to check the values of a struct from an image/binary file?

c,gcc,binaryfiles
Is there anyway i can look into the values of a structure after compilation? objdump -td gives the function definitions and only the address where the structure is stored. The problem is i am getting a wrong address for one of the threads/functions in a structure when i run a...

GCC emits vastly different code using “-march=native” on similar architectures

c,gcc,assembly,sse,avx
I'm working on writing an OpenCL benchmark in C. Currently, it measures the fused multiply-accumulate performance of both a CL device, and the system's processor using C code. The results are then cross checked for accuracy. I wrote the native code to take advantage of GCC's auto vectorizer, and it...

C++ GCC/MinGW Paths: ssp, ext, tr1; parallel, ext, bits, experimental

c++,gcc,clang,mingw-w64,libc++
Question: In the GCC/MinGW folder tree, there are duplicates of some header file names, in folders: ssp, ext, tr1; parallel, ext, bits, and experiemental ... Should explicit "include" directives for these folders be avoided in production code--as a best practice? OR, is there documentation online, regarding the legitimate scenarios these...

Why does gcc search header files from non-exist folders?

c,linux,gcc,compiler-errors,make
I am trying to build an open source project shark on CentOS 7, and get very weird build errors: make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h', needed by `core/luv/luv.o'. make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h', needed by `core/luv/luv.o'. make: *** No rule to make target `/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h', needed...

gcc compile multiple files

c++,c,gcc,compiler-errors
I have these five source main.c src_print1.c src_print2.c header_print1.h header_print2.h the contents are simple and are as following for respective files: main.c #include "header_print1.h" #include "header_print2.h" int main(int argc, char** argv) { print1(); print2(); return 0; } header_print1.h #ifndef PRINT_1 #define PRINT_1 #include <stdio.h> #include <stdlib.h> void print1(); #endif header_print2.h...

Makefile with two targets and two languages

c++,c,gcc,makefile
I work with C and C++ and thanks to this answer I was able to compile and run my project. Now I am writing a makefile to spare time. But things are getting complicated : Project structure project makefile client bin src c cc java server ... # Directories #...

How -s option works actually in gcc compilers?

gcc,g++,command-line-interface
gcc & g++ provides command line option -s to reduce the size of executable file. But I want to know that how this -s option works exactly? What it does so that size of the executable reduces? How the size of file gets reduced?

[ performance]— string::operator+= vs. vector push_back

c++,string,gcc,vector,char
I was testing the performance between these two operations, and on G++ 4.7.3, the string::operator+= version is about 2 times faster. My simple test: What can be the cause of such a big difference? g++ -O2 --std=c++11 #include <iostream> #include <ctime> #include <string> #include <vector> using namespace std; class Timer...

gcc make dependency and object simultaneously

gcc,makefile,g++
I am using gcc 4.8.2, and I am trying to build both the object file and the dependency file concurrently. This works: $ g++ -std=c++11 -MP -MD -c foo.cxx -o foo.o $ [ -s foo.d ] && [ -s foo.o ] && echo yay yay However, instead of generating foo.d,...

How can I convert an int to a string in C++11 without using to_string or stoi?

c++,string,c++11,gcc
I know it sounds stupid, but I'm using MinGW32 on Windows7, and "to_string was not declared in this scope." It's an actual GCC Bug, and I've followed these instructions and they did not work. So, how can I convert an int to a string in C++11 without using to_string or...

Placing a global constant array into `.rodata` section

c,gcc,static
The goal is to place a large array of constant data into .rodata section with allowing the access to it from other translation units. As far as I know, GCC would place a data into the read-only section if declared as static const. But then it is impossible to declare...

__cplusplus < 201402L return true in gcc even when I specified -std=c++14

c++,gcc,g++,c++14,predefined-macro
The directive: #ifndef __cplusplus #error C++ is required #elif __cplusplus < 201402L #error C++14 is required #endif The command-line: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp My g++ version: g++ (tdm-1) 4.9.2 The error C++14 is required is generated even when I added -std=c++14, I don't know why. Please...

Constructing priority_queue instance with Compare instance of different type

c++,gcc,constructor,containers
Could anybody please explain why my compiler (GCC) accepts the code below as valid? priority_queue<int, deque<int>, less<int>> pq(greater<int>()); I expect this constructor (for an instance of type having less<int> as Comparator, as specified for priority_queue instance pq) to be incompatible with an instance of greater<int> (passed as constructor parameter), which...

How to use use precompiled static libraries with MinGW?

c,linux,windows,gcc,mingw
I am trying to use MinGW to compile Linux project into Windows. I have been successful doing so with Cygwin, but I would match rather prefer to use MinGW so I the program does not end up having dozens of unnecessary dependencies. Unfortunately, I have run into a problem that...

Excluding GNU as (GAS) standard startup code [closed]

c,gcc,gnu,gas,gnu-arm
I want the GCC to exclude the startup code it link automatically with building process what should i do? So that i have my Own Startup assembly code defining labels (_start, _exit,..etc)...

gcc compilation with linker - differences

c,gcc,linker
This will compile main.c and link created .o file statically with with abc library and dynamically with xyz gcc main.c -Wl,-Bstatic -labc -Wl,-Bdynamic -lxyz -o main But I am not sure about some other combinations: This will compile main.c to main - but what -lm will do in this case?...

Scoping rules for struct variables in GCC

c,gcc,struct,clang,scoping
Consider the following C program #include <stdio.h> typedef struct s { int x; } s_t; int main() { int x; s_t a; scanf("%d", &x); if (x > 0) { s_t a; a.x = x; } printf("%d\n", a.x); } The a struct variable in the if branch clearly shadows the a...

Why does defining main() with no return type compile with no error?

c++,gcc
I was just testing this code by compiling it with GCC (g++); #include <stdio.h> main(int argc, char **argv){ printf("something"); } It seems to build and run fine with just a warning saying; ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] Though I defined main() with no return type...

non-static data member initialization with new expression

c++,c++11,gcc,language-lawyer
Consider the following code: #include <map> template <typename T> struct X { std::map<int, T>* storage = new std::map<int, T>(); }; int main() { X<int> x; } This compiles on clang 3.6.0, but fails to compile on gcc 5.1. It would compile, however, if the type of storage were instead std::vector<T>*...

Error by Compiler gcc: undefined reference to `main'

c,linux,algorithm,sorting,gcc
I am writting this program for K_ mean clustering in C and Compiling this program on GCC compiler in Linux Compiler error massages are following ***/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status*** My complete Programme is following #include <stdlib.h> #include <assert.h> #include...

How is it that “sizeof (char[0])” compiles just fine with GCC

c,gcc
A colleague of mine inserted a (void) sizeof (char[0]) at the end of a multi line, macro as an alternative to do {...} while (0) apparently. I have looked around but I can't find any reference to it and it surprises me that it even compiles. Is it valid C?...

Why Unicode characters are not displayed properly in terminal with GCC?

c,gcc,unicode
I've written a small C program: #include <stdio.h> #include <stdlib.h> #include <locale.h> int main() { wprintf(L"%s\n", setlocale(LC_ALL, "C.UTF-8")); wchar_t chr = L'┐'; wprintf(L"%c\n", chr); } Why doesn't this print the character ┐ ? Instead it prints gibberish. I've checked: tried compiling without setlocale, same result the terminal itself can print...

SIGFPE with gcc and unsigned integers

c,gcc,floating-point,c11,sigfpe
I'm getting this weird behaviour from an executable compiled with different versions of gcc, all emit the SIGFPE signal and the best part is that I have no floating point of any kind in my code; if someone could shed some light on this ... I literally don't know where...

lowest() is not a member of std::numeric_limits

c++,gcc,qt-creator
I am trying to compile the following code: #include <iostream> #include <limits> int main() { std::cout << std::numeric_limits<int>::lowest() << std::endl; } and I get the following error: ../main.cpp:5: error: 'lowest' is not a member of 'std::numeric_limits<int>' cout << std::numeric_limits<int>::lowest() << std::endl; ^ I am using QT Creator 3.1.1 on Ubuntu...

What distinguishes these LAPACK programmes? One compiles, the other does not

c,gcc,lapack
I have two programmes using the LAPACK routine dgeev in C. One appears to be working, the other does not compile claiming undefined reference to dgeev. I seek to understand why. The first code below - called mamapack.c - produces sensible results when compiled and run like this: [email protected]:~/Desktop/tests$ gcc...

Is free() zeroing out memory?

c,gcc,memory-management,clang,free
Until today I lived in belief that calling free() on memory space releases it for further allocation without any other modifications. Especially, considering this SO question that clearly states that free() DOESN'T zero out memory. Yet, let's consider this piece of code (test.c): #include<stdlib.h> #include<stdio.h> int main() { int* pointer;...

x86 asm - 12 bytes subtracted from esp. Only 8 needed

gcc,assembly,x86
I've compiled this code with gcc (gcc -ggdb -mpreferred-stack-boundary=2 -o demo demo.c) and decompiled it to look at the assembly (I know it's using unsafe functions, this was for an exercise into buffer overflows): #include<stdio.h> CanNeverExecute() { printf("I can never execute\n"); exit(0); } GetInput() { char buffer[8]; gets(buffer); puts(buffer); }...

Tell C++ that pointer data is 16 byte aligned

c++,gcc,sse,memory-alignment
I wrote some code with static arrays and it vectorizes just fine. float data[1024] __attribute__((aligned(16))); I would like to make the arrays dynamically allocated. I tried doing something like this: float *data = (float*) aligned_alloc(16, size*sizeof(float)); But the compiler (GCC 4.9.2), no longer can vectorize the code. I assume this...

Fatal error: iostream: No such file or directory in compiling C program using GCC

c,gcc
Why when I wan to compile the following multi thread merge sorting C program, I receive this error: [email protected]:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpthread mer.c:4:20: fatal error: iostream: No such file or directory #include <iostream> ^ compilation terminated. [email protected]:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpthread mer.c:4:22: fatal...

using ‘-Wcast-qual’ option to check the compilation

c,gcc
I am reading an introduction to gcc in which it says: ‘-Wcast-qual’ this option warns about pointers that are cast to remove a type qualifier, such as const. For example, the following function discards the const qualifier from its input argument, allowing it to be overwritten: void f (const char...

Why size of an empty array is 0 but size of an empty class is not 0?

c++,gcc,g++
For example: int main() { struct {} foo; int bar[0]; struct { int dummy[0]; } baz; cout << sizeof(foo) << endl; //display '1' cout << sizeof(bar) << endl; //display '0' cout << sizeof(baz) << endl; //display '0' return 0; } Please tell me is there any reason stand behind that...

Make c++ macro2 containt quoted body of macro1

c++,gcc,c-preprocessor,qmake
I'm trying to make some kind of a simple system that calculates the number of builds, including this info in .rc file (for windows) and met the problem. Here it is: #define QUOTE(s) #s #define A 0,0,0,1 #define A_STR QUOTE(A) Expanding of A_STR: "A" but not "0,0,0,1" as I expected....

Ambiguous reference to variable

gcc,fortran,fortran90,gfortran,intel-fortran
So I am doing 2 modules which are linking to the main program. The first one has all the variables defined in it and the second one is with the functions. Module1: module zmienne implicit none integer, parameter :: ngauss = 8 integer, parameter :: out_unit=1000 integer, parameter :: out_unit1=1001...