How does GCC’s ‘-pg’ flag work in relation to profilers?

Compiling with -pg instruments your code, so that Gprof reports detailed information. See gprof’s manual, 9.1 Implementation of Profiling: Profiling works by changing how every function in your program is compiled so that when it is called, it will stash away some information about where it was called from. From this, the profiler can figure … Read more

gcc optimization flags for Xeon?

An update for recent GCC / Xeon. Sandy-Bridge-based Xeon (E3-12xx series, E5-14xx/24xx series, E5-16xx/26xx/46xx series). -march=corei7-avx for GCC < 4.9.0 or -march=sandybridge for GCC >= 4.9.0. This enables the Advanced Vector Extensions support as well as the AES and PCLMUL instruction sets for Sandy Bridge. Here’s the overview from the GCC i386/x86_64 options page: Intel … Read more

Can we see the templates instantiated by the C++ compiler?

Clang (https://clang.llvm.org/) can pretty-print AST of instantiated template: For your example: test.cpp template < class T> T add(T a, T b){ return a+b; } void tmp() { add<int>(10,2); } Command to pretty-print AST: $ clang++ -Xclang -ast-print -fsyntax-only test.cpp Clang-5.0/Clang 14.0 output: template <class T> T add(T a, T b) { return a + b; … Read more

@JvmDefault and how add compiler option

@Target([AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY]) annotation class JvmDefault Specifies that a JVM default method should be generated for non-abstract Kotlin interface member. Usages of this annotation require an explicit compilation argument to be specified: either -Xjvm-default=enable or -Xjvm-default=compatibility. with -Xjvm-default=enable, only default method in interface is generated for each @JvmDefault method. In this mode, annotating an existing method … Read more

Changing CMAKE_CXX_FLAGS in project

The most straightforward solution should be using add_compile_options() if you are using version 2.8.12 or newer. For older versions you can “abuse” add_definitions(). While it is only meant for add -D flags, it also works with any other compiler flag. However, I think it is not meant to be used that way and could break … Read more

Does set_target_properties in CMake override CMAKE_CXX_FLAGS?

The accepted answer is still working but outdated since 2013. This answer is based and new functions from CMake v2.8.12, v3.3 and v3.13. Since CMake-2.8.12 (2013) Two new commands to set CMAKE_CXX_FLAGS: target_compile_options() (for one single target) add_compile_options() (for all targets) The documentation of last version has not changed a lot since cmake-2.8.12: target_compile_options() add_compile_options() … Read more