How can I override the C++ compiler CMake uses for CUDA? - c++

I'm using a CUDA version which does not support the GCC version installed on my system (my GCC is too new). I'm trying to build a repository which uses CMake for build configuration.
I know how to override the C++ compiler, traditionally:
export CXX=/path/to/other/compiler-binary
and CMake picks this up. I can also use cmake -DCMAKE_CXX_COMPILER. However, neither of these options work when compiling CUDA host-side code: CMake still has CUDA try to use my default GCC version on my system.
How can I tell it to use the alternative C++ compiler for CUDA?
Additional info:
CMake 3.22.1
On Devuan GNU/Linux Chimaera

CMake will not (for now) default to using your CMAKE_CXX_COMPILER as the C++ compiler for CUDA host-side code; there's a different setting for that. Run your build configuration like so:
cmake -DCMAKE_CUDA_HOST_COMPILER=/usr/bin/g++-9
(replace the path with to your chosen C++ compiler of course)

Related

Headers for Clang from VS build tools and LLVM

I was experimenting with different compilers, build managers and IDEs for my new project in C++. I am using VSCode(v1.52) on a windows 10 machine. I installed VS build tools 2019 and also included C++ Clang Compiler for Windows and C++ Clang-cl for v142 build tools (x64/x86). The project uses CMake as build manager and a plug-in CMake tools have been installed as well. Setup works fine as it is now.
However, I just want to know what are the differences to include Clang compiler from VSCode build tools 2019 and from LLVM. Does Clang that comes with VSCode build tools uses its own headers or the headers from VS? I do not want to use if Clang uses headers from VS..!
VSCode build tools (C++ Clang tools for Windows) will link the Clang compiler with Microsoft implementation of the Standard Library
Also, VSCode build tools has a component called: "C++ Clang-cl for v142" that gives you the freedom of using your own Compiler/Settings
Regarding header files, on Windows you should use clang with either GCC (Open Source) or MSVC header files.
I could not find the exact source of the header files in VS Build tools. However, as said above, it will link the compiler with Microsoft STL.
To install Clang with GCC header files (Works on VsCode):
go to https://www.msys2.org/ and install mysys2
then open mysys2 terminal and copy those commands to install Clang:
pacman -S mingw-w64-x86_64-clang
pacman -S mingw-w64-x86_64-clang-tools-extra
dont forget to add \msys64\mingw64\bin to the SYSTEM PATH variable
I have also made a video, with step by step: https://youtu.be/5OSO8IRlyXc

How can I use different Xcode versions for different branches (or latest Xcode with different Clang versions)?

We compile different branches of our project with different versions of Xcode, because it has different versions of the c++ compiler "clang" built-in. And a new compiler not only means new features, but unfortunately also new compiler bugs (hence new workarounds). So we want to keep the compiler once we branched a stable version of our project, but always use the latest compiler for the trunk.
Installing several Xcode versions is easy: We just add the Version number to the name and so we get:
/Applications/Xcode9
/Applications/Xcode10
/Applications/Xcode11
For the integration server and other scripts the required version can easily be picked and started with
xcode-select -s /Applications/Xcode10.app
xcodebuild -project myproj.xcodeproj build
But for working on the different branches with Xcode as graphical IDE this proves to be quite a problem:
Unlike Visual Studio Solutions (.sln and .vcxproj), Xcode Projects (.xcproj) don't support the specification of an IDE version they open in.
Different versions of Xcode don't play well together and seem to overwrite each others settings and caches (e.g. which projects/windows that were open, and even build status).
My last hope of solving this is to always use the latest Xcode IDE, but let it use an earlier compiler version.
There seems to be a project setting under Build Options for this, called Compiler for C/C++/Objective-C (GCC_VERSION when set via .xcconfig) with the standard value Default Compiler (Apple Clang) (com.apple.compilers.llvm.clang.1_0).
However, I was not able to find another valid value that I could use there. So far, I have tried clang version number and path to the clang executable (e.g. /Applications/Xcode10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang). Xcode always says Unsupported Compiler.
So what is the correct way to specify another compiler version in Xcode? Or do you know another approach to solve the original problem?
I found a way to use an older clang version in latest IDE. This example works for using the Apple LLVM version 10.0.0 (clang-1000.11.45.2) in the Xcode 11.3:
In the .xcconfig file (Menu->File->New->File, "Configuration Settings File"), the compiler paths can be set explicitly with
CC = /Applications/Xcode10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
CPLUSPLUS = /Applications/Xcode10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
But this is not enough: The system header files of a newer Xcode installation are sometimes incompatible with the old compiler. We need to set the roots for these files accordingly
OTHER_CFLAGS = -isysroot /Applications/Xcode10.app/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

How to create CMake cross-compiling toolchain for VxWorks?

I want to generate vxworks 6.x makefiles and workspace via CMake, and there is no support for VxWroks in CMake. How do I create a relevant generator for my platform anf the correct toolchain?
I'm new to CMake. I managed to create some test project that generate for windows VS 2015 and Ubuntu.
I tried to create one for VxWorks 6.x with GNU and DIAB compiler, but there is no support for it in CMake.
I read about something called toolchain, cross-compiling and platform files (.cmake) but I don't understand how to write it and where to put it.
I saw many examples in the internet but didn't understand if I need to rebuild the CMake with the new platform files or just reference to them form the toolchain or from CMakeLists.
I'm using the gui version of CMake 3.14.
I setting the generator as: Eclipse CDT4 - Unix Makefiles.
When I choosing the option of cross-compiling and provide name VxWorks, version, c++ compiler (gnu/4.1.2-vxworks-6.6/x86-win32/bin/c++ppc.exe), it write that the compiler is unknown and that I need to create Platform/VxWroks. It cannot build a simple test program.
I saw some post of someone who succeeded to create all required files :
Do (Cross-compile) platform files require an include guard?
But I couldn't download some examples to test it and a tutorial of how to do it.
I would like to be able to cgreate a generator with CMake for VxWorks 6.x to cimpile libraries and exacutable (.vxe) but don't know what to do.
CMake is not well supported in VxWorks 6, but CMake is supported from the Workbench/Eclipse GUI environment in VxWorks 7. Neither version supports command line cmake, e.g. "cmake ."

How to setup CLion with portable Clang on ubuntu?

I want to test Clang with CLion in ubuntu. By default Clion detects my gcc installation, but I want to use clang instead of gcc. Moreover, I don't want to install clang via apt-get. I have downloaded llvm, clang (3.6.2) binary from llvm website. I want to use that portable clang binaries.
Here is my system setup:
Ubuntu - 14.04
gcc - 4.8.4
llvm clang - 3.6.2 (portable)
CLion - 1.0.4
So how to set up CLion with llvm-clang here?
I got the answer from CLion blog and it works and here it goes.
To provide CMake compiler paths, go to Settings | Build, Execution, Deployment | CMake and pass as CMake options:
-D CMAKE_C_COMPILER=
-D CMAKE_CXX_COMPILER=
In case CMake fails to find some path to clang libs, etc. you can also set there environment variables:
CC=/usr/bin/clang
CXX=/usr/bin/clang++
The FAQ states the following:
At present CLion supports GCC and Clang compilers and is guided by these two to get the libraries and headers paths. In the next releases we are planning to extend the list of compilers available in CLion.
To change the compiler, go to the Cache tab in CMake tool window and set the compiler’s path to the CMAKE_CXX_COMPILER variable. Then press Enter and click the Apply Changes and Reload button

Run my code on older version of linux

I am new to Linux programming and I wonder, is there a way to run (not recompile) my C++ executable on an older version of Linux of the same distribution?
Example: Say I compiled my code on RHEL 6 and want to run my executable on RHEL 4 or 5.
In Windows when we do this we just install the C++ runtime of the compiler version of C++.
Example: If I use VS2012 to build a C++ project using C++11, I just need to install the C++ runtime of C++11 on the client machine to run my application no matter what version of Windows I am using (of course starting from Windows XP)
The by far easiest way is to make use of the strong future compatibility of glibc and the GCC runtime libraries: compile your executable on the oldest OS you want it to run on, and it should work on anything later without recompiling (that is, some symlinks may be needed to satisfy the dependencies the executable loader is expecting).
In general it is best to compile it for each distribution you want to support, so no unexpected conflicts appear.
Actually, yes - Find your apps deps (using e.g: ldd) and copy them (e.g: libstdc++.so.6) from your build system to somewhere on your target system (e.g: /mylibs). Point your app here (e.g: using patchelf's --rpath and --interpreter). Your app should run (test it!). If not, it's likely that your glibc is incompatible with the older kernel. You can solve this by recompiling the required version of glibc to support the older kernel - using the --enable-kernel=<version> ./configure switch. If your required version of glibc doesn't support that kernel version then you can supply the missing functions in .so's and load them with LD_PRELOAD.