![](/img/trans.png)
[英]Add linker flag in CMake and execute automatically a gcc command
[英]Cmake automatically defaults to gcc-5
我正在嘗試使用 cmake 編譯 amber 工具。我使用的是 ubuntu Ubuntu 16.04.7 LTS,默認版本為 gcc gcc-5 和 g++5,而 amber 工具至少需要 gcc-6。 我已經安裝了 gcc-8 和 g++8,並使用 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
謝謝
我不會將其稱為 CMake 的問題,而是 Amber 通過 CMake 執行編譯器控制的方式,這很可能是通過采用環境變量 $PATH 中出現的第一個編譯器來執行的。
如果你仍然想編譯它,我可以建議兩種便宜的方法:
update-alternatives
package,更改“系統默認值”gcc 和 g++export PATH=absolute/path/to/a/folder:$PATH
,並在此路徑中放置兩個符號鏈接,分別稱為 gcc 和 g++,指向 gcc-8 和 g++-8 據此,您仍在使用在設置新的C
和CXX
編譯器之前生成的現有緩存文件。
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
,您正在從構建文件夾中運行它。 一般來說,我建議使用語法cmake -S[source] -B[build]
。 您當前的工作目錄應該被完全刪除。 一旦你這樣做,重新運行你的cmake
命令,它應該被正確設置。
如果它不起作用,您可以通過添加來進行健全性檢查
set(CMAKE_C_COMPILER [path_to_C])
set(CMAKE_CXX_COMPILER [path_to_CXX])
請務必將其放在 CMAKELISTS 文件的開頭,即在任何project()
行之前。
編輯:你也聽說過 docker 嗎? 它是為使用遺留工具創建特殊封閉環境的絕佳工具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.