Cmake自动默认为gcc-5

w41d8nur  于 2023-01-20  发布在  其他
关注(0)|答案(2)|浏览(143)

我尝试使用cmake编译琥珀色工具。我使用的是ubuntu Ubuntu 16.04.7 LTS,默认的gcc版本为gcc-5和g5,琥珀色工具至少需要gcc-6。我已经安装了gcc-8和g8,并使用CMAKE_C_COMPILER和CMAKE_CXX_COMPILER指定了它。使用的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 \

即使指定了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

谢谢

yeotifhr

yeotifhr1#

我不认为这是CMake的问题,而是Amber通过CMake执行编译器控制的方式,这很可能是通过获取环境变量$PATH中出现的第一个编译器来执行的。
如果您想编译它,我可以建议两种廉价的方法:

  • 使用update-alternatives包,更改“系统默认值”gcc和g++
  • 在PATH中的路径前面添加export PATH=absolute/path/to/a/folder:$PATH,并在此路径中放置两个符号链接gcc和g++,它们分别指向gcc-8和g++-8
bwntbbo3

bwntbbo32#

因此,您仍然使用在设置新的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

基于cmake $AMBER_PREFIX/amber22_src,你可以从你的build文件夹中运行这个命令。一般来说,我推荐使用语法cmake -S[source] -B[build]。你当前的工作目录应该被完全删除。一旦你完成了这个操作,重新运行你的cmake命令,它应该被正确设置。
如果它不起作用,您可以通过添加

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

确保将其放在Cmakelists文件的开头,即任何project()行之前。

编辑:你听说过Docker吗?它是一个很好的工具,可以为使用遗留工具创建特殊的包含环境。

相关问题