compiler-flags

How to add compiler flags on codeblocks

你。 提交于 2019-11-26 16:56:12
问题 I've been trying to compile a simple multithreaded piece of code I found online in an effort to learn how to multithread. To run this piece of code I need to use the compiler flags: -pthread and -std=c++0x . But whenever I try to add the flags the build log doesn't show them being used. I've tried some generic tips online to get these to work, but none of them worked. Can someone help? I've tried other advice online to add compiler flags to code blocks, but when I do that and check the build

How do I force gcc to inline a function?

懵懂的女人 提交于 2019-11-26 15:20:39
Does __attribute__((always_inline)) force a function to be inlined by gcc? Yes. From documentation always_inline Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level was specified. It should. I'm a big fan of manual inlining. Sure, used in excess it's a bad thing. But often times when optimizing code, there will be one or two functions that simply have to be inlined or performance goes down the toilet. And frankly, in my experience C compilers typically do not inline those

How to set CUDA compiler flags in Visual Studio 2010?

烈酒焚心 提交于 2019-11-26 11:34:11
问题 After persistently getting error : identifier \"atomicAdd\" is undefined , I\'ve found the solution to be to compile with -arch sm_20 flag. But how to pass this compiler flag in VS 2010? I have tried like so under Project > Properties : But this apparently has had no effect and the error persists - what am I doing wrong? Many thanks. 回答1: You can select the options for the GPU Code Generation in this dialog: In this case "compute_20" means that i am compiling for the virtual compute

How to see which flags -march=native will activate?

爷,独闯天下 提交于 2019-11-26 08:57:41
问题 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 it actually using? 回答1: You can use the -Q --help=target options: gcc -march=native -Q --help=target ... The -v option may also be of use. You can see the documentation on the --help option here. 回答2: To see command-line flags, use: gcc -march

Is optimisation level -O3 dangerous in g++?

对着背影说爱祢 提交于 2019-11-26 08:54:18
问题 I have heard from various sources (though mostly from a colleague of mine), that compiling with an optimisation level of -O3 in g++ is somehow \'dangerous\', and should be avoided in general unless proven to be necessary. Is this true, and if so, why? Should I just be sticking to -O2 ? 回答1: In the early days of gcc (2.8 etc.) and in the times of egcs, and redhat 2.96 -O3 was quite buggy sometimes. But this is over a decade ago, and -O3 is not much different than other levels of optimizations

Useful GCC flags for C

梦想的初衷 提交于 2019-11-26 07:51:32
问题 Beyond setting -Wall , and setting -std=XXX , what other really useful, but less known compiler flags are there for use in C? I\'m particularly interested in any additional warnings, and/or and turning warnings into errors in some cases to absolutely minimize any accidental type mismatches. 回答1: Several of the -f code generation options are interesting: The -ftrapv function will cause the program to abort on signed integer overflow (formally "undefined behaviour" in C). -fverbose-asm is

How do I force gcc to inline a function?

≯℡__Kan透↙ 提交于 2019-11-26 04:21:54
问题 Does __attribute__((always_inline)) force a function to be inlined by gcc? 回答1: Yes. From documentation always_inline Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level was specified. 回答2: It should. I'm a big fan of manual inlining. Sure, used in excess it's a bad thing. But often times when optimizing code, there will be one or two functions that simply have to be inlined or

Difference between -pthread and -lpthread while compiling

做~自己de王妃 提交于 2019-11-26 00:43:21
问题 What is the difference between gcc -pthread and gcc -lpthread which is used while compiling multithreaded programs? 回答1: -pthread tells the compiler to link in the pthread library as well as configure the compilation for threads. For example, the following shows the macros that get defined when the -pthread option gets used on the GCC package installed on my Ubuntu machine: $ gcc -pthread -E -dM test.c > dm.pthread.txt $ gcc -E -dM test.c > dm.nopthread.txt $ diff dm.pthread.txt dm.nopthread