Home > Software engineering >  Cmake automatically defaults to gcc-5
Cmake automatically defaults to gcc-5

Time:01-18

I was trying to compile amber tools using cmake. I am using ubuntu Ubuntu 16.04.7 LTS with the default gcc version gcc-5 and g 5, and amber tool requires at least gcc-6. I have installed gcc-8 and g 8 and specified it using the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. The cmake command used is the command below:

cmake $AMBER_PREFIX/amber22_src \
-DCMAKE_INSTALL_PREFIX=$AMBER_PREFIX/amber22 \
-DCOMPILER=GNU \
-DMPI=FALSE -DCUDA=TRUE -DINSTALL_TESTS=TRUE \
-DDOWNLOAD_MINICONDA=TRUE \
-DCMAKE_C_COMPILER=/usr/bin/gcc-8 -DCMAKE_CXX_COMPILER=/usr/bin/g  -8 \

Even though the gcc g is specified I get the following error:

-- Starting configuration of Amber version 22.0.0...
-- CMake Version: 3.14.0
-- For how to use this build system, please read this wiki:
--     http://ambermd.org/pmwiki/pmwiki.php/Main/CMake
-- For a list of important CMake variables, check here:
--     http://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Common-Options
-- **************************************************************************
-- Setting C compiler to gcc
-- Setting CXX compiler to g  
-- Setting Fortran compiler to gfortran
-- Amber source not found, only building AmberTools
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- The Fortran compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g  
-- Check for working CXX compiler: /usr/bin/g   -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
-- 
************************************************************
Error: Amber requires at least g  -6.0
See https://ambermd.org/Installation.php for more info
************************************************************
-- 
CMake Error at cmake/VerifyCompilerConfig.cmake:30 (message):
Call Stack (most recent call first):
  cmake/AmberBuildSystem2ndInit.cmake:30 (include)
  CMakeLists.txt:111 (include)


-- Configuring incomplete, errors occurred!
See also "/media/gpu-1/GPU_1_2TB/Ambertools22/amber22_src/build/CMakeFiles/CMakeOutput.log".
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/bin/gcc-8
CMAKE_CXX_COMPILER= /usr/bin/g  -8

-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    DOWNLOAD_MINICONDA
    MPI


-- Build files have been written to: /media/gpu-1/GPU_1_2TB/Ambertools22/amber22_src/build

If the cmake build report looks OK, you should now do the following:

    make install
    source /media/gpu-1/GPU_1_2TB/Ambertools22/amber22/amber.sh

Thank you

CodePudding user response:

I would not call it a problem of CMake, rather on the way Amber performs the control of the compiler, which most likely is performed by taking the first compiler that appears from the environment variable $PATH.

If you would like to compile it anyway, I can suggest two cheap ways:

  • using the update-alternatives package, to change the "system default" gcc and g
  • prepend a path in PATH with export PATH=absolute/path/to/a/folder:$PATH, and in this path put two symbolic links called gcc and g , that points at gcc-8 and g -8

CodePudding user response:

According to this, you are still using existing cache files that you've generated before you set the new C and CXX compiler.

You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/bin/gcc-8
CMAKE_CXX_COMPILER= /usr/bin/g  -8

Based on cmake $AMBER_PREFIX/amber22_src you are running this from your build folder. In general I recommend using the syntax cmake -S[source] -B[build]. Your current working directory should be completely deleted. Once you do that, re-run your cmake command and it should be correctly set.

If it doesn't work you can do a sanity check by adding

set(CMAKE_C_COMPILER [path_to_C])
set(CMAKE_CXX_COMPILER [path_to_CXX])

BE SURE TO PUT IT AT THE START OF THE CMAKELISTS FILE i.e. before any project() line.

EDIT: Also have you heard about docker? It's a great tool for creating special contained environments for using legacy tools.

  • Related