GCC with -march : invalid switch - c++11

OS: Ubuntu 16.04 s390x
Gcc: Build from source v7.3.0 using steps mentioned below:
mkdir gcc
cd gcc
wget https://ftpmirror.gnu.org/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz
tar -xf gcc-7.3.0.tar.xz
cd gcc-7.3.0
./contrib/download_prerequisites
mkdir objdir
cd objdir
../configure --prefix=/opt/gcc --enable-languages=c,c++ --enable-shared --with-system-zlib --enable-threads=posix --enable-__cxa_atexit --enable-checking --enable-gnu-indirect-function --disable-bootstrap --disable-multilib
make
make install
ln -sf /opt/gcc/bin/gcc /usr/bin/gcc
ln -sf /opt/gcc/bin/g++ /usr/bin/g++
ln -sf /opt/gcc/bin/g++ /usr/bin/c++
export PATH=/opt/gcc/bin:"$PATH"
export LD_LIBRARY_PATH=/opt/gcc/lib64:"$LD_LIBRARY_PATH"
export C_INCLUDE_PATH=/opt/gcc/lib/gcc/s390x-linux-gnu/7.3.0/include
export CPLUS_INCLUDE_PATH=/opt/gcc/lib/gcc/s390x-linux-gnu/7.3.0/include
sudo ln -sf /opt/gcc/lib64/libstdc++.so.6.0.24 /usr/lib/s390x-linux-gnu/libstdc++.so.6
gcc --version
gcc (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
Then on compiling code for cockroachDB using make. Build fails with an error:
Error: invalid switch -march=z14
Error: unrecognized option -march=z14
Is there any flag which needs to enable here?
(No such error was observed if gcc is installed from repo using apt-get install g++-7 on Ubuntu 18.04)

-march-z14 was added after the GCC 7 release to GCC 8 in this commit and to GCC 7 in this commit. This commit went into the GCC 7.2 minor release, as far as I can tell, so GCC 7.3 should have it.
The error message is not a GCC error message, though. (Only code in the Ada front end calls command line option “switches”.) The build process uses something else from the Ubuntu 16.04 system which does not recognize -march=z14.
You may be able to use march=arch12 as a workaround. (The 12 refers to the edition of the Principles of Operation, which is currently off by two.)

Related

CentOS 7 Upgraded gcc / g++ but can't seem to use it?

I used the script to upgrade gcc/g++ to v5.4. The script ran successfully and the new libraries were supposedly installed to /usr/lib64
Still, when I gcc --version it tells me its 4.8.5 still. There is no gcc directory in /usr/lib64 and the one in /usr/lib only contains a gcc directory folder for 4.8.5
Any help is appreciated!!
Perhaps it's an issue with creating a symbolic link to gcc-4.8
cd /usr/bin
sudo rm gcc
sudo ln -s gcc-4.8 gcc
then test
gcc --version
And see if you got it. If not, you can
sudo yum remove path/packageName
and reinstall

cmake error using the mingw-w64-x86_64 gcc toolchain under Windows 7 : "this program has been built without plugin support"

I have a setup with Windows 7, MSYS2, Mingw-w64-x86_64 gcc toolchain, CMake, and I am trying to build the nanomsg library.
Here is what I obtain :
$ cmake --debug-trycompile
-DCMAKE_TOOLCHAIN_FILE=../toolchain_i686-pc-mingw32.cmake -DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32 -G "MinGW Makefiles" ../nanomsg
debug trycompile on
-- The C compiler identification is GNU 4.8.2
-- Check for working C compiler: C:/mingw64/bin/x86_64-w64-mingw32-gcc.exe
-- Check for working C compiler: C:/mingw64/bin/x86_64-w64-mingw32-gcc.exe -- broken CMake Error at
C:/cmake-win32-x86/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61
(message): The C compiler
"C:/mingw64/bin/x86_64-w64-mingw32-gcc.exe" is not able to compile a
simple test program.
It fails with the following output:
Change Dir:
C:/msys64/home/Laurent/Dev/nanomsg-build/CMakeFiles/CMakeTmp
Run Build Command:C:/mingw64/bin/mingw32-make.exe
"cmTryCompileExec910276652/fast"
C:/mingw64/bin/mingw32-make.exe -f
CMakeFiles\cmTryCompileExec910276652.dir\build.make
CMakeFiles/cmTryCompileExec910276652.dir/build
mingw32-make.exe1: Entering directory
'C:/msys64/home/Laurent/Dev/nanomsg-build/CMakeFiles/CMakeTmp'
C:\cmake-win32-x86\bin\cmake.exe -E cmake_progress_report
C:\msys64\home\Laurent\Dev\nanomsg-build\CMakeFiles\CMakeTmp\CMakeFiles
1
Building C object
CMakeFiles/cmTryCompileExec910276652.dir/testCCompiler.c.obj
C:\mingw64\bin\x86_64-w64-mingw32-gcc.exe -o
CMakeFiles\cmTryCompileExec910276652.dir\testCCompiler.c.obj -c
C:\msys64\home\Laurent\Dev\nanomsg-build\CMakeFiles\CMakeTmp\testCCompiler.c
Linking C executable cmTryCompileExec910276652.exe
C:\cmake-win32-x86\bin\cmake.exe -E cmake_link_script
CMakeFiles\cmTryCompileExec910276652.dir\link.txt --verbose=1
C:\cmake-win32-x86\bin\cmake.exe -E remove -f
CMakeFiles\cmTryCompileExec910276652.dir/objects.a
x86_64-w64-mingw32-gcc-ar cr
CMakeFiles\cmTryCompileExec910276652.dir/objects.a
#CMakeFiles\cmTryCompileExec910276652.dir\objects1.rsp
sorry - this program has been built without plugin support
CMakeFiles\cmTryCompileExec910276652.dir\build.make:91: recipe for
target 'cmTryCompileExec910276652.exe' failed
mingw32-make.exe1: * [cmTryCompileExec910276652.exe] Error 1
mingw32-make.exe1: Leaving directory
'C:/msys64/home/Laurent/Dev/nanomsg-build/CMakeFiles/CMakeTmp'
Makefile:116: recipe for target 'cmTryCompileExec910276652/fast'
failed
mingw32-make.exe: * [cmTryCompileExec910276652/fast] Error 2
CMake will not be able to correctly generate this project. Call
Stack (most recent call first): CMakeLists.txt:29 (project)
Here is my toolchain file:
$ cat ../toolchain_i686-pc-mingw32.cmake
# http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file
# http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=8959
# http://stackoverflow.com/questions/19754316/cross-compiling-opencv-with-mingw-using-cmakein-linux-for-windows
# this one is important
SET(CMAKE_SYSTEM_NAME Windows)
#this one not so much
#SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(PREFIX x86_64-w64-mingw32)
SET(CMAKE_MAKE_PROGRAM mingw32-make)
SET(CMAKE_C_COMPILER ${PREFIX}-gcc)
SET(CMAKE_CXX_COMPILER ${PREFIX}-g++)
SET(CMAKE_AR ${PREFIX}-gcc-ar)
SET(CMAKE_NM ${PREFIX}-gcc-nm)
SET(CMAKE_RC_COMPILER windres)
# specify the cross linker
SET(CMAKE_RANLIB ${PREFIX}-gcc-ranlib)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /opt/mingw64 /usr/${PREFIX})
# search for programs in the build host directories
#SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
#SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
It looks like it fails to build on an auto test because the toolchain misses plugin support.
Here is my gcc version and options:
$ /opt/mingw64/bin/x86_64-w64-mingw32-gcc.exe -v
Using built-in specs.
COLLECT_GCC=C:\mingw64\bin\x86_64-w64-mingw32-gcc.exe
COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.2/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.8.2/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw482/x86_64-482-posix-seh-rt_v3-rev3/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw482/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw482/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw482/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw482/prerequisites/x86_64-w64-mingw32-static --with-cloog=/c/mingw482/prerequisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh-rev3, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw482/x86_64-482-posix-seh-rt_v3-rev3/mingw64/opt/include -I/c/mingw482/prerequisites/x86_64-zlib-static/include -I/c/mingw482/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw482/x86_64-482-posix-seh-rt_v3-rev3/mingw64/opt/include -I/c/mingw482/prerequisites/x86_64-zlib-static/include -I/c/mingw482/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw482/x86_64-482-posix-seh-rt_v3-rev3/mingw64/opt/lib -L/c/mingw482/prerequisites/x86_64-zlib-static/lib -L/c/mingw482/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 4.8.2 (x86_64-posix-seh-rev3, Built by MinGW-W64 project)
Is it related to the "--enable-plugin" option (missing in my gcc) ?
Is there somewhere a toolchain build available with this option set ? I looked for it in MSYS2, Mingw-w64, rubenvb repositories, but it is not there. Or shall I build it myself ?
Possibly nanomsg does not need it ? Does the autotest requires it because nanomsg needs it ? Or can I prevent this autotest from being run ? Or can I set something to avoid the need of the "--enable-plugins" option ?
I think you are using the MSYS2 shell here, and not MSYS2 itself. If you were using an up to date MSYS2 then you'd be using the following mingw-w64 x86_64 GCC:
$ pacman -Ss mingw-w64-x86_64-gcc
mingw64/mingw-w64-x86_64-gcc 4.9.1-6
$ PATH=/mingw64/bin:$PATH gcc -v
Configured with: ... --enable-lto ...
--enable-lto implies --enable-plugins which is the default now and so doesn't appear in the list.
To build nanomsg with MSYS2, install https://master-dl.sourceforge.net/project/msys2/Base/x86_64/msys2-x86_64-20141003.exe, untick "Run MSYS2 shell now" (you want a mingw-w64 shell instead). Run the mingw-w64 shell (Start->MSYS2 64Bit->MinGW-w64 Win64 Shell). From within that shell:
$ pacman -S git make mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc
$ git clone https://github.com/nanomsg/nanomsg.git
$ mkdir nanomsg-build
$ cd nanomsg-build
$ cmake --debug-trycompile -DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32 -G "MSYS Makefiles" ../nanomsg
$ make install
But if you are a developer, we'd appreciate the contribution of a PKGBUILD for nanomsg

Building GCC 4.8.2 in OS X 10.9

I'm trying to compile and install GCC 4.8.2 in OS X 10.9. I followed the instructions here (http://gcc.gnu.org/wiki/InstallingGCC) to first run ./contrib/download_prerequesites and then ran configure and make from a directory different from the source. My build fails with error:
checking for suffix of object files... configure: error: in `/Users/prokilogrammer/temp/gcc-build482/x86_64-apple-darwin13.0.2/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
Apparently this problem would be solved if GCC's dependencies (GMP, MPC, MPFR) are properly installed (http://gcc.gnu.org/wiki/FAQ#configure_suffix). I checked and made sure they are correctly installed under /usr/local/lib & /usr/local/include directories.
Looking at config.log, I see the following errors:
configure:3565: checking for suffix of object files
configure:3587: /Users/prokilogrammer/temp/gcc-build482/./gcc/xgcc -B/Users/prokilogrammer/temp/gcc-build482/./gcc/ -B/usr/local/x86_64-apple-darwin13.0.2/bin/ -B/usr/local/x86_64-apple-darwin13.0.2/lib/ -isystem /usr/local/x86_64-apple-darwin13.0.2/include -isystem /usr/local/x86_64-apple-darwin13.0.2/sys-include -c -g -O2 conftest.c >&5
conftest.c:1:0: internal compiler error: Segmentation fault: 11
/* confdefs.h */
^
libbacktrace could not find executable to open
I am not sure if the segfault is because of the missing dependencies or a legit issue in gcc.
Have you guys experienced similar problems? Is there a solution/workaround?
PS: I have also tried setting LD_LIBRARY_PATH & DYLD_LIBRARY_PATH without any luck.
I've built GCC 4.8.2 on several Mavericks machines, but I chose a slightly different strategy. Specifically, I included the code for GMP, MPC, MPFR (and CLOOG and ISL) in the build directory. I used a script to quasi-automate it:
GCC_VER=gcc-4.8.2
tar -xf ${GCC_VER}.tar.bz2 || exit 1
cd ${GCC_VER} || exit
cat <<EOF |
cloog 0.18.0 tar.gz
gmp 5.1.3 tar.xz
isl 0.11.1 tar.bz2
mpc 1.0.1 tar.gz
mpfr 3.1.2 tar.xz
EOF
while read file vrsn extn
do
tar -xf "../$file-$vrsn.$extn" &&
ln -s "$file-$vrsn" "$file"
done
With that done:
mkdir gcc-4.8.2-obj
cd gcc-4.8.2-obj
../gcc-4.8.2/configure --prefix=$HOME/gcc/v4.8.2
make -j8 bootstrap
AFAICR, that was about all it took, with 4.8.1 and 4.8.2.

Issue linking g++-4.8 Mac OSX 10.8

I downloaded gcc v4.8 from homebrew so that I could update gcc and g++ to 4.8 instead of using the 4.2.1 supplied from apple.
I installed gcc48 with the following command:
$brew install gcc48 --enable-all-languages
This installed all the required dependancies and when I run,
$gcc-4.8 -v
I get:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc48/4.8.1/gcc/libexec/gcc/x86_64-apple-darwin12.4.0/4.8.1/lto-wrapper
Target: x86_64-apple-darwin12.4.0
Configured with: ../configure --build=x86_64-apple-darwin12.4.0 --prefix=/usr/local/Cellar/gcc48/4.8.1/gcc --datarootdir=/usr/local/Cellar/gcc48/4.8.1/share --bindir=/usr/local/Cellar/gcc48/4.8.1/bin --enable-languages=c,c++,fortran,java,objc,obj-c++ --program-suffix=-4.8 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-plugin --enable-lto --disable-werror --disable-nls --with-ecj-jar=/usr/local/opt/ecj/share/java/ecj.jar --disable-multilib
Thread model: posix
gcc version 4.8.1 (GCC)
I created the symbolic link using
$ln -s gcc-4.8 gcc
while in the /usr/local/bin folder and it created the symbolic link and
$gcc -v
gives me the same output as:
$gcc-4.8 -v
I tried doing the same thing with g++-4.8 and created a symbolic link using,
$ln -s g++-4.8 g++
and got no errors. But now, when I do
$g++ -v
I get:
g++-4.8: error trying to exec '/usr/local/bin/../Cellar/gcc48/4.8.1/bin/i686-apple-darwin11-llvm-g++-4.2': execvp: No such file or directory
Here's my $PATH:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/Developer/Intel/ispc-v1.3.0-osx:/Developer/NVIDIA/CUDA-5.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin
It seems to be looking for 4.2 for some reason and I have no idea why! It worked perfectly fine for gcc and am just not sure what is the problem with g++?
which g++
returns
/usr/local/bin/g++
Try running:
$ hash
And check if gcc is in the list. If it is you may need to run:
$ hash -r
If you use bash or:
$ rehash
For zsh. This refreshes the hash, which provides a way for the shell to find the command without rechecking the entire path each time.
Looks to me that your g++ symbolic link points to the wrong thing.
Try:
ls -l `which g++`
And if that looks OK, see if the target is not a symbolic link too, etc..
Be mindful that symbol links use relative paths. If you move a symbolic link around, it doesn't point to the same location anymore.
Hope that helps.

CUDA incompatible with my gcc version

I have troubles compiling some of the examples shipped with CUDA SDK.
I have installed the developers driver (version 270.41.19) and the CUDA toolkit,
then finally the SDK (both the 4.0.17 version).
Initially it didn't compile at all giving:
error -- unsupported GNU version! gcc 4.5 and up are not supported!
I found the line responsible in 81:/usr/local/cuda/include/host_config.h and changed it to:
//#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)
from that point on I got only a few of the examples to compile, it stops with:
In file included from /usr/include/c++/4.6/x86_64-linux-gnu/bits/gthr.h:162:0,
from /usr/include/c++/4.6/ext/atomicity.h:34,
from /usr/include/c++/4.6/bits/ios_base.h:41,
from /usr/include/c++/4.6/ios:43,
from /usr/include/c++/4.6/ostream:40,
from /usr/include/c++/4.6/iterator:64,
from /usr/local/cuda/include/thrust/iterator/iterator_categories.h:38,
from /usr/local/cuda/include/thrust/device_ptr.h:26,
from /usr/local/cuda/include/thrust/device_malloc_allocator.h:27,
from /usr/local/cuda/include/thrust/device_vector.h:26,
from lineOfSight.cu:37:
/usr/include/c++/4.6/x86_64-linux-gnu/bits/gthr-default.h:251:1: error: pasting "__gthrw_" and "/* Android's C library does not provide pthread_cancel, check for
`pthread_create' instead. */" does not give a valid preprocessing token
make[1]: *** [obj/x86_64/release/lineOfSight.cu.o] Error 1
As some of the examples compile I reckon this is not a driver problem, but rather must have something to do with an unsupported gcc version. Downgrading is not an option as gcc4.6 has a whole system as a dependency at this point...
As already pointed out, nvcc depends on gcc 4.4. It is possible to configure nvcc to use the correct version of gcc without passing any compiler parameters by adding softlinks to the bin directory created with the nvcc install.
The default cuda binary directory (the installation default) is /usr/local/cuda/bin, adding a softlink to the correct version of gcc from this directory is sufficient:
sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc
Check the maximum supported GCC version for your CUDA version:
CUDA version
max supported GCC version
12
12.1
11.4.1+, 11.5, 11.6, 11.7, 11.8
11
11.1, 11.2, 11.3, 11.4.0
10
11
9
10.1, 10.2
8
9.2, 10.0
7
9.0, 9.1
6
8
5.3
7
4.9
5.5, 6
4.8
4.2, 5
4.6
4.1
4.5
4.0
4.4
Set an env var for that GCC version. For example, for CUDA 10.2:
MAX_GCC_VERSION=8
Make sure you have that version installed:
sudo apt install gcc-$MAX_GCC_VERSION g++-$MAX_GCC_VERSION
Add symlinks within CUDA folders:
sudo ln -s /usr/bin/gcc-$MAX_GCC_VERSION /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-$MAX_GCC_VERSION /usr/local/cuda/bin/g++
(or substitute /usr/local/cuda with your CUDA installation path, if it's not there)
See this GitHub gist for more information on the CUDA-GCC compatibility table.
gcc 4.5 and 4.6 are not supported with CUDA - code won't compile and the rest of the toolchain, including cuda-gdb, won't work properly. You cannot use them, and the restriction is non-negotiable.
Your only solution is to install a gcc 4.4 version as a second compiler (most distributions will allow that). There is an option to nvcc --compiler-bindir which can be used to point to an alternative compiler. Create a local directory and then make symbolic links to the supported gcc version executables. Pass that local directory to nvcc via the --compiler-bindir option, and you should be able to compile CUDA code without affecting the rest of your system.
EDIT:
Note that this question, and answer, pertain to CUDA 4.
Since it was written, NVIDIA has continued to expand support for later gcc versions in newer CUDA toolchain release
As of the CUDA 4.1 release, gcc 4.5 is now supported. gcc 4.6 and 4.7 are unsupported.
As of the CUDA 5.0 release, gcc 4.6 is now supported. gcc 4.7 is unsupported.
As of the CUDA 6.0 release, gcc 4.7 is now supported.
As of the CUDA 7.0 release, gcc 4.8 is fully supported, with 4.9 support on Ubuntu 14.04 and Fedora 21.
As of the CUDA 7.5 release, gcc 4.8 is fully supported, with 4.9 support on Ubuntu 14.04 and Fedora 21.
As of the CUDA 8 release, gcc 5.3 is fully supported on Ubuntu 16.06 and Fedora 23.
As of the CUDA 9 release, gcc 6 is fully supported on Ubuntu 16.04, Ubuntu 17.04 and Fedora 25.
The CUDA 9.2 release adds support for gcc 7
The CUDA 10.1 release adds support for gcc 8
The CUDA 10.2 release continues support for gcc 8
The CUDA 11.0 release adds support for gcc 9 on Ubuntu 20.04
The CUDA 11.1 release expands gcc 9 support across most distributions and adds support for gcc 10 on Fedora linux
There is presently (as of CUDA 11.1) no gcc 10 support in CUDA other than Fedora linux
Note that NVIDIA has recently added a very useful table here which contains the supported compiler and OS matrix for the current CUDA release.
Gearoid Murphy's solution works better for me since on my distro (Ubuntu 11.10), gcc-4.4 and gcc-4.6 are in the same directory, so --compiler-bindir is no help. The only caveat is I also had to install g++-4.4 and symlink it as well:
sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-4.4 /usr/local/cuda/bin/g++
If using cmake for me none of the hacks of editing the files and linking worked so I compiled using the flags which specify the gcc/g++ version.
cmake -DCMAKE_C_COMPILER=gcc-6 -DCMAKE_CXX_COMPILER=g++-6 ..
Worked like charm.
For CUDA7.5 these lines work:
sudo ln -s /usr/bin/gcc-4.9 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-4.9 /usr/local/cuda/bin/g++
Check out how to use "update-alternatives" to get around this issue:
... If you install gcc 4.6 you can also use the update-alternatives
command to allow for easily switching between versions. This can be
configured with:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
sudo update-alternatives --config gcc
On most distributions you have the possibility to install another gcc and g++ version beside a most recent compiler like gcc-4.7. In addition most build systems are aware of the CC and CXX environment variables, which let specify you other C and C++ compilers respectively. SO I suggest something like:
CC=gcc-4.4 CXX=g++-4.4 cmake path/to/your/CMakeLists.txt
For Makefiles there should be a similar way. I do not recommend setting custom symlinks within /usr/local unless you know what you are doing.
This works for fedora 23. The compat gcc repositories will be slightly different based on your version of fedora.
If you install the following repositories:
sudo yum install compat-gcc-34-c++-3.4.6-37.fc23.x86_64 compat-gcc-34-3.4.6-37.fc23.x86_64
Now make the soft links as mentioned above assuming your cuda bin folder is in /usr/local/cuda/
sudo ln -s /usr/bin/gcc-34 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-34 /usr/local/cuda/bin/g++
You should now be able to compile with nvcc without the gcc version error.
Gearoid Murphy's solution works like a charm. For me I had two directories for cuda -
/usr/local/cuda
/usr/local/cuda-5.0
The soft links had to be added only to the directory mentioned below -
/usr/local/cuda
Also, both g++ and gcc soft links were required as mentioned by SchighSchagh.
Another way of configuring nvcc to use a specific version of gcc (gcc-4.4, for instance), is to edit nvcc.profile and alter PATH to include the path to the gcc you want to use first.
For example (gcc-4.4.6 installed in /opt):
PATH += /opt/gcc-4.4.6/lib/gcc/x86_64-unknown-linux-gnu/4.4.6:/opt/gcc-4.4.6/bin:$(TOP)/open64/bin:$(TOP)/share/cuda/nvvm:$(_HERE_):
The location of nvcc.profile varies, but it should be in the same directory as the nvcc executable itself.
This is a bit of a hack, as nvcc.profile is not intended for user configuration as per the nvcc manual, but it was the solution which worked best for me.
CUDA is after some header modifications compatible with gcc4.7 and maybe higher version:
https://www.udacity.com/wiki/cs344/troubleshoot_gcc47
For people like me who get confused while using cmake, the FindCUDA.cmake script overrides some of the stuff from nvcc.profile. You can specify the nvcc host compiler by setting CUDA_HOST_COMPILER as per http://public.kitware.com/Bug/view.php?id=13674.
I had to install the older versions of gcc, g++.
sudo apt-get install gcc-4.4
sudo apt-get install g++-4.4
Check that gcc-4.4 is in /usr/bin/, and same for g++
Then I could use the solution above:
sudo ln -s /usr/bin/gcc-4.4 /opt/cuda/bin/gcc
sudo ln -s /usr/bin/g++-4.4 /opt/cuda/bin/g++
In $CUDA_HOME/include/host_config.h, find lines like these (may slightly vary between different CUDA version):
//...
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9)
#error -- unsupported GNU version! gcc versions later than 4.9 are not supported!
#endif [> __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) <]
//...
Remove or change them matching your condition.
Note this method is potentially unsafe and may break your build. For example, gcc 5 uses C++11 as default, however this is not the case for nvcc as of CUDA 7.5. A workaround is to add
--Xcompiler="--std=c++98" for CUDA<=6.5
or
--std=c++11 for CUDA>=7.0.
If you encounter this error, please read the log file:
$ cat /var/log/cuda-installer.log
[INFO]: Driver installation detected by command: apt list --installed | grep -e nvidia-driver-[0-9][0-9][0-9] -e nvidia-[0-9][0-9][0-9]
[INFO]: Cleaning up window
[INFO]: Complete
[INFO]: Checking compiler version...
[INFO]: gcc location: /usr/bin/gcc
[INFO]: gcc version: gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)
[ERROR]: unsupported compiler version: 9.2.1. Use --override to override this check.
Just follow the suggestion in the log file:
sudo sh cuda_<version>_linux.run --override
Job done :)
I just installed CUDA 10.2 with gcc 9.2 on Kubuntu 19.10 using the --override option.
For CUDA 6.5 (and apparently 7.0 and 7.5), I've created a version of the gcc 4.8.5 RPM package (under Fedora Core 30) that allows that version of gcc to be install alongside your system's current GCC.
You can find all of that information here.
To compile the CUDA 8.0 examples on Ubuntu 16.10, I did:
sudo apt-get install gcc-5 g++-5
cd /path/to/NVIDIA_CUDA-8.0_Samples
# Find the path to the library (this should be in NVIDIA's Makefiles)
LIBLOC=`find /usr/lib -name "libnvcuvid.so.*" | head -n1 | perl -pe 's[/usr/lib/(nvidia-\d+)/.*][$1]'`
# Substitute that path into the makefiles for the hard-coded, incorrect one
find . -name "*.mk" | xargs perl -pi -e "s/nvidia-\d+/$LIBLOC/g"
# Make using the supported compiler
HOST_COMPILER=g++-5 make
This has the advantage of not modifying the whole system or making symlinks to just the binaries (that could cause library linking problems.)
This solved my problem:
sudo rm /usr/local/cuda/bin/gcc
sudo rm /usr/local/cuda/bin/g++
sudo apt install gcc-4.4 g++-4.4
sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-4.4 /usr/local/cuda/bin/g++
In my case, I had CUDA already installed from the Ubuntu version and cmake would detect that one instead of the newly installed version using the NVidia SDK Manager.
I ran dpkg -l | grep cuda and could see both versions.
What I had to do is uninstall the old CUDA (version 9.1 in my case) and leave the new version alone (version 10.2). I used the purge command like so:
sudo apt-get purge libcudart9.1 nvidia-cuda-dev nvidia-cuda-doc \
nvidia-cuda-gdb nvidia-cuda-toolkit
Please verify that the package names match the version you want to remove from your installation.
I had to rerun cmake from a blank BUILD directory to redirect all the #include and libraries to the SDK version (since the old paths were baked in the existing build environment).
This is happening because your current CUDA version doesn't support your current GCC version. You need to do the following:
Find the supported GCC version (in my case 5 for CUDA 9)
CUDA 4.1: GCC 4.5
CUDA 5.0: GCC 4.6
CUDA 6.0: GCC 4.7
CUDA 7.0: GCC 4.8
CUDA 7.5: GCC 4.8
CUDA 8: GCC 5.3
CUDA 9: GCC 5.5
CUDA 9.2: GCC 7
CUDA 10.1: GCC 8
Install the supported GCC version
sudo apt-get install gcc-5
sudo apt-get install g++-5
Change the softlinks for GCC in the /usr/bin directory
cd /usr/bin
sudo rm gcc
sudo rm g++
sudo ln -s /usr/bin/gcc-5 gcc
sudo ln -s /usr/bin/g++-5 g++
Change the softlinks for GCC in the /usr/local/cuda-9.0/bin directory
cd /usr/local/cuda-9.0/bin
sudo rm gcc
sudo rm g++
sudo ln -s /usr/bin/gcc-5 gcc
sudo ln -s /usr/bin/g++-5 g++
Add -DCUDA_HOST_COMPILER=/usr/bin/gcc-5 to your setup.py file, used for compilation
if torch.cuda.is_available() and CUDA_HOME is not None:
extension = CUDAExtension
sources += source_cuda
define_macros += [("WITH_CUDA", None)]
extra_compile_args["nvcc"] = [
"-DCUDA_HAS_FP16=1",
"-D__CUDA_NO_HALF_OPERATORS__",
"-D__CUDA_NO_HALF_CONVERSIONS__",
"-D__CUDA_NO_HALF2_OPERATORS__",
"-DCUDA_HOST_COMPILER=/usr/bin/gcc-5"
]
Remove the old build directory
rm -rd build/
Compile again by setting CUDAHOSTCXX=/usr/bin/gcc-5
CUDAHOSTCXX=/usr/bin/gcc-5 python setup.py build develop
Note: If you still get the gcc: error trying to exec 'cc1plus': execvp: no such file or directory error after following these steps, try reinstalling the GCC like this and then compiling again:
sudo apt-get install --reinstall gcc-5
sudo apt-get install --reinstall g++-5
Credits: https://github.com/facebookresearch/maskrcnn-benchmark/issues/25#issuecomment-433382510

Resources