Sometimes you may want to add a specific compiler flag to the build commands used to build your code by Eclipse CDT. For example, say you want to add the -std=c++11 flag to build your code. Adding this is easy:
Go to Project > Properties > C/C++ Build > Settings > Cross G++ Compiler > Miscellaneous
In the Other flags entry, append your flag. In this case, we append -std=c++11
That is it! Eclipse CDT will use this flag to compile your code.
Eclipse CDT uses gcc, g++ and as as the C compiler, C++ compiler (and linker) and assembler by default. Sometimes, you may want to use a different version or different type of compiler, linker or assembler to build your code. Changing this in Eclipse CDT for your project is easy:
Go to Project > Properties > C/C++ Build > Settings > Tool Settings.
In this dialog, to change the C++ compiler, change the entry in Cross G++ Compiler > Command.
In this dialog, to change the C compiler, change the entry in Cross GCC Compiler > Command.
In this dialog, to change the C++ linker, change the entry in Cross G++ Linker > Command. This is typically the same as the C++ compiler command.
In this dialog, to change the assembler, change the entry in Cross GCC Assembler > Command.
Click Apply and OK. Build your code and you will see that the new tools are used.
Sometimes you might need to use a different version of a default compiler (like gcc) or a different compiler (like Intel compiler) to build your code. Specifying this is easy in CMake. Add these lines to your CMakeLists.txt:
The __CUDA_ARCH__ macro is defined only for device code. It is a macro that identifies the CUDA architecture version that the NVCC compiler is compiling the code for. When defined, it holds a 3-digit value of the form xy0, which indicates a particular CUDA architecture. For example, sm_20 is stored as 200, sm_13 as 130 and so on.
This macro is useful to compile different code for host and device:
__host__ __device__ void foobar()
// Device specific code
// Host specific code
This macro is also useful to write device code that is specific to particular architectures:
__global__ void fooKernel()
#if __CUDA_ARCH__ >= 200
// Code that uses advanced features
// introduced in sm_20 and later
// Fallback code for older architectures
Reference: Section on Virtual Architecture Identification Macro in the NVCC Manual.