简体   繁体   English

Cmake 自动默认为 gcc-5

[英]Cmake automatically defaults to gcc-5

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.我正在尝试使用 cmake 编译 amber 工具。我使用的是 ubuntu Ubuntu 16.04.7 LTS,默认版本为 gcc gcc-5 和 g++5,而 amber 工具至少需要 gcc-6。 I have installed gcc-8 and g++8 and specified it using the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER.我已经安装了 gcc-8 和 g++8,并使用 CMAKE_C_COMPILER 和 CMAKE_CXX_COMPILER 指定了它。 The cmake command used is the command below: cmake使用的命令是下面的命令:

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:即使指定了 gcc g++,我也会收到以下错误:

-- 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谢谢

I would not call it a problem of CMake, rather on the way Amber performs the control of the compiler through CMake, which most likely is performed by taking the first compiler that appears from the environment variable $PATH.我不会将其称为 CMake 的问题,而是 Amber 通过 CMake 执行编译器控制的方式,这很可能是通过采用环境变量 $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++使用update-alternatives package,更改“系统默认值”gcc 和 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在 PATH 中添加一个路径export PATH=absolute/path/to/a/folder:$PATH ,并在此路径中放置两个符号链接,分别称为 gcc 和 g++,指向 gcc-8 和 g++-8

According to this, you are still using existing cache files that you've generated before you set the new C and CXX compiler.据此,您仍在使用在设置新的CCXX编译器之前生成的现有缓存文件。

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.基于cmake $AMBER_PREFIX/amber22_src ,您正在从构建文件夹中运行它。 In general I recommend using the syntax cmake -S[source] -B[build] .一般来说,我建议使用语法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.一旦你这样做,重新运行你的cmake命令,它应该被正确设置。

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 ie before any project() line.请务必将其放在 CMAKELISTS 文件的开头,即在任何project()行之前。

EDIT: Also have you heard about docker?编辑:你也听说过 docker 吗? It's a great tool for creating special contained environments for using legacy tools.它是为使用遗留工具创建特殊封闭环境的绝佳工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM