计算化学公社

标题: 利用cmake编译和安装CP2K [打印本页]

作者
Author:
UW_0728.    时间: 2026-1-2 17:41
标题: 利用cmake编译和安装CP2K
本帖最后由 UW_0728. 于 2026-2-11 18:10 编辑

从版本2026.1开始,CP2K的编译将全面转为cmake,彻底放弃原有的GNU makefile和相应的arch文件集。个人感觉在cmake下编译比传统的编译模式报错概率更低一点。然而,目前toolchain尚未实现针对自定义的配置设计合适的cmake指令,因此只能自己根据CMakeLists.txt里面的选项逐个添加与既有toolchain配置相对应的到命令行中,比较麻烦,且开发者貌似并不打算解决这一点;另外,目前无法通过cmake同时编译ssmp和psmp(检测出MPI就只编译psmp,否则只编译ssmp),且编译成的程序没有相应的符号链接sopt和popt,不过这不算什么大问题,毕竟psmp同时支持MPI和OpenMP并行,只要设置OMP_NUM_THREADS为物理核心数且不用mpirun指令就相当于运行ssmp,只要export OMP_NUM_THREADS=1 并利用mpirun -np N (N为并行核数)运行就相当于运行popt了;此外,我发现CP2K对sopt/popt版本中相应设置的实现是通过Fortran主代码中的几行完成的,因此实际上你完全可以在二进制文件目录下自己创建这样的符号链接。(补充:目前开发分支已经在cmake的install一步加回了popt和sopt符号链接的创建命令)

接下来讲一讲从cmake编译CP2K可执行文件的基本步骤:(假设为root用户,使用2026.1版本;更早版本用传统模式编译更省事一点)

1. 按照社长的文章(http://sobereva.com/586)正常完成toolchain工具链安装步骤,然后执行source /root/CP2K/src/cp2k-2026.1/tools/toolchain/install/setup

2. 切到cp2k源码目录,执行mkdir build && cd build,进入构建和编译专用目录。

3. 运行构建指令。如上所述,这里需要手动输入构建选项。假如完全按照社长文章里的选项配置好toolchain,那么你所需要的cmake命令为:
cmake .. -DCMAKE_INSTALL_PREFIX=../install -DCP2K_USE_MPI=ON -DCP2K_USE_FFTW3=ON -DCP2K_USE_LIBINT2=ON -DCP2K_USE_LIBXC=ON -DCP2K_USE_SPGLIB=ON -DCP2K_USE_VORI=ON -DCP2K_USE_COSMA=ON -DCP2K_USE_ELPA=ON -DCP2K_USE_LIBXSMM=ON -DCP2K_USE_PLUMED=ON -DCP2K_USE_SIRIUS=ON -DCP2K_USE_TBLITE=ON -DCP2K_DATA_DIR=/root/CP2K/src/cp2k-2026.1/data

这里包括toolchain默认安装的,以及根据自己的设置选择多安装或不安装的包。命令中的-DCMAKE_INSTALL_PREFIX 设置到自己想安装到的路径(可以使用相对路径;为省事我直接设置在了父目录下的一个新文件夹;如果不设置,默认将为/usr/local)。由于OpenBLAS是强制性的、Scalapack在有MPI的情况下是强制性的,因此无论如何它们都会被检查,这里无需写出。之所以特别设置-DCP2K_DATA_DIR=/root/CP2K/src/cp2k-2026.1/data是因为cmake构建系统安装好后默认读取基组的位置是${CMAKE_INSTALL_PREFIX}/shared/cp2k/data,会导致编译时生成与/root/CP2K/src/cp2k-2026.1/data内容完全重复的/root/CP2K/src/cp2k-2026.1/install/shared/cp2k/data目录,加上这一设置可以避免这一问题(但注意这里不能使用相对路径)

2026-01-26补充:根据
https://github.com/cp2k/cp2k/commit/9513a73f5c67e4b564ec780b7019669123e3b5ce目前的CP2K开发分支已经能够在toolchain安装结束时给出与toolchain设置相匹配的CMake配置选项,预计下一个版本2026.2中会包含。大家可以直接看那里面的文件修改详情(generate_cmake_options.sh在后来也有些细节上的修补),然后把经修改和添加的文件直接复制粘贴到自己下载好的源代码包相应位置,就可以正常用了;此时toolchain安装结束后会在最后输出推荐的cmake选项,可以直接将整个命令复制粘贴使用。

4. 构建完成后,运行
make install -jN,N是并行核数。

5. 写入以下三行至~/.bashrc中以添加环境变量:
export PATH=$PATH:/root/CP2K/src/cp2k-2026.1/install/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/CP2K/src/cp2k-2026.1/install/lib64
source /root/CP2K/src/cp2k-2026.1/tools/toolchain/install/setup


6. 如果硬盘有点吃紧,可以
删除该build文件夹(或者不删除但在build目录内执行make clean)以腾出部分空间。

作者
Author:
m1racle    时间: 2026-1-7 22:31
  1. [root[url=home.php?mod=space&uid=84862]@m1racle[/url] build]# cmake -S .. -DCMAKE_INSTALL_PREFIX=.. -DCP2K_USE_MPI=ON -DCP2K_USE_FFTW3=ON -DCP2K_USE_LIBINT2=ON -DCP2K_USE_LIBXC=ON -DCP2K_USE_SPGLIB=ON -DCP2K_USE_VORI=ON -DCP2K_USE_COSMA=ON -DCP2K_USE_ELPA=ON -DCP2K_USE_LIBXSMM=ON -DCP2K_USE_HDF5=ON -DCP2K_USE_PLUMED=ON
  2. -- Checking for module 'mpi-c'
  3. --   Package 'mpi-c', required by 'virtual:world', not found
  4. -- Could NOT find MPI_C (missing: MPI_C_LIB_NAMES MPI_C_HEADER_DIR MPI_C_WORKS)
  5. -- Checking for module 'mpi-cxx'
  6. --   Package 'mpi-cxx', required by 'virtual:world', not found
  7. -- Could NOT find MPI_CXX (missing: MPI_CXX_LIB_NAMES MPI_CXX_HEADER_DIR MPI_CXX_WORKS)
  8. -- Checking for module 'mpi-fort'
  9. --   Package 'mpi-fort', required by 'virtual:world', not found
  10. -- Could NOT find MPI_Fortran (missing: MPI_Fortran_LIB_NAMES MPI_Fortran_F77_HEADER_DIR MPI_Fortran_MODULE_DIR MPI_Fortran_WORKS)
  11. CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  12.   Could NOT find MPI (missing: MPI_C_FOUND MPI_CXX_FOUND MPI_Fortran_FOUND C
  13.   CXX Fortran)
  14. Call Stack (most recent call first):
  15.   /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
  16.   /usr/share/cmake/Modules/FindMPI.cmake:1837 (find_package_handle_standard_args)
  17.   CMakeLists.txt:409 (find_package)

  18. -- Configuring incomplete, errors occurred!
复制代码

你好,运行构建指令的时候出现如上报错,请问怎么解决,cmake是直接dnf install装的,toolchain按照sob老师博文安装的,谢谢

作者
Author:
UW_0728.    时间: 2026-1-7 22:37
m1racle 发表于 2026-1-7 22:31
你好,运行构建指令的时候出现如上报错,请问怎么解决,cmake是直接dnf install装的,toolchain按照sob老 ...

没检查到MPI。source那一步做了没有
作者
Author:
m1racle    时间: 2026-1-7 22:59
做了,但是之后我发现没装cmake,我退出去装cmake了,估计是还要在执行一遍这个命令,我试试
作者
Author:
m1racle    时间: 2026-1-7 23:02
UW_0728. 发表于 2026-1-7 22:37
没检查到MPI。source那一步做了没有
  1. -- Checking for one of the modules 'elpa_openmp'
  2. -- Found Elpa: /root/cp2k-2026.1/tools/toolchain/install/elpa-2024.05.001/cpu/lib/libelpa_openmp.so;/root/cp2k-2026.1/tools/toolchain/install/scalapack-2.2.2/lib/libscalapack.a;:libopenblas.a
  3. CMake Error at tools/toolchain/install/cmake-3.31.7/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
  4.   Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS C Fortran)
  5. Call Stack (most recent call first):
  6.   tools/toolchain/install/cmake-3.31.7/share/cmake-3.31/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
  7.   tools/toolchain/install/cmake-3.31.7/share/cmake-3.31/Modules/FindHDF5.cmake:1027 (find_package_handle_standard_args)
  8.   CMakeLists.txt:657 (find_package)
复制代码

这次每检查到HDF5
作者
Author:
UW_0728.    时间: 2026-1-7 23:08
本帖最后由 UW_0728. 于 2026-1-7 23:19 编辑
m1racle 发表于 2026-1-7 23:02
这次每检查到HDF5


我看了下2026.1的toolchain脚本,发现默认选项为with_hdf5="__DONTUSE__",即默认不安装HDF5。把cmake里面-DCP2K_USE_HDF5=ON去掉吧(最好先清空build文件夹)

CP2K这个默认选项与help信息里提示的竟然不一致,这是我没想到的。。

作者
Author:
m1racle    时间: 2026-1-7 23:12
UW_0728. 发表于 2026-1-7 23:08
我看了下2026.1的toolchain脚本,发现默认选项为with_hdf5="__DONTUSE__",即默认不安装HDF5。把cmake里 ...

ok,我来试一下,谢谢你
作者
Author:
m1racle    时间: 2026-1-7 23:30
UW_0728. 发表于 2026-1-7 23:08
我看了下2026.1的toolchain脚本,发现默认选项为with_hdf5="__DONTUSE__",即默认不安装HDF5。把cmake ...

1,是这个问题,现在编译成功了
2,你的环境配置,第一行少了个斜杠/
谢谢大佬
作者
Author:
UW_0728.    时间: 2026-1-8 00:56
m1racle 发表于 2026-1-7 23:30
1,是这个问题,现在编译成功了
2,你的环境配置,第一行少了个斜杠/
谢谢大佬

抱歉,没懂第二点的意思
作者
Author:
m1racle    时间: 2026-1-8 23:05
UW_0728. 发表于 2026-1-8 00:56
抱歉,没懂第二点的意思

cp2k-2026.1/bin
作者
Author:
UW_0728.    时间: 2026-1-8 23:32
m1racle 发表于 2026-1-8 23:05
cp2k-2026.1/bin

感谢,已修正
作者
Author:
Qilin    时间: 2026-1-13 15:41
把下面三行直接写入 `~/.bashrc` 会把初学者拐带坏的。再不济也应该写入 `~/env/cp2k_2026.1.env`。
```
export PATH=$PATH:/root/CP2K/src/cp2k-2026.1/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/CP2K/src/cp2k-2026.1/lib64
source /root/CP2K/src/cp2k-2026.1/tools/toolchain/install/setup
```
这才看到,天呐,这个人是在 root 权限下安装的。可以说很邪恶了。

作者
Author:
jmliu    时间: 2026-1-16 16:45
老师您好,我的系统是ubuntu 20.04,cpu是amd,我在编译cp2k2026.1的cmake的步骤使用cmake -S .. -DCP2K_USE_EVERYTHING=ON -DCP2K_USE_DLAF=OFF -DCP2K_USE_PEXSI=OFF -DCP2K_USE_LIBSMEAGOL=OFF -DCP2K_USE_DEEPMD=OFF -DCP2K_USE_ACE=OFF -DCP2K_USE_TREXIO=OFF -DCP2K_USE_GREENX=OFF -DCP2K_USE_LIBTORCH=OFF -DCP2K_USE_MIMIC=OFF会出现这个报错-- multicharge: Find installed package
CMake Error at CMakeLists.txt:793 (find_package):
  By not providing "Findtoml-f.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "toml-f", but
  CMake did not find one.

  Could not find a package configuration file provided by "toml-f" with any
  of the following names:

    toml-fConfig.cmake
    toml-f-config.cmake

  Add the installation prefix of "toml-f" to CMAKE_PREFIX_PATH or set
  "toml-f_DIR" to a directory containing one of the above files.  If "toml-f"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!修改build命令成cmake -S .. -DCP2K_USE_DLAF=OFF -DCP2K_USE_PEXSI=OFF -DCP2K_USE_LIBSMEAGOL=OFF -DCP2K_USE_DEEPMD=OFF -DCP2K_USE_ACE=OFF -DCP2K_USE_TREXIO=OFF -DCP2K_USE_GREENX=OFF -DCP2K_USE_LIBTORCH=OFF -DCP2K_USE_MIMIC=OFF -DCP2K_DATA_DIR=/home/ljm_test/software/cp2k-2026.1/data -DCP2K_USE_SPLA=ON -DCP2K_USE_SIRIUS=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_INSTALL_PREFIX=/home/ljm_test/software/cp2k-2026.1/exe/可以正常运行但是在最后make install步骤会报错(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/memory_utilities_unittest.dir/build.make:125: bin/memory_utilities_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:379: src/CMakeFiles/memory_utilities_unittest.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/gx_ac_unittest.dir/build.make:125: bin/gx_ac_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:667: src/CMakeFiles/gx_ac_unittest.dir/all] Error 2
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/gemm_square_unittest.dir/build.make:125: bin/gemm_square_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:347: src/CMakeFiles/gemm_square_unittest.dir/all] Error 2
[ 98%] Built target libcp2k_unittest
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/nequip_unittest.dir/build.make:125: bin/nequip_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:571: src/CMakeFiles/nequip_unittest.dir/all] Error 2
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/parallel_rng_types_unittest.dir/build.make:125: bin/parallel_rng_types_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:411: src/CMakeFiles/parallel_rng_types_unittest.dir/all] Error 2
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/dbt_tas_unittest.dir/build.make:125: bin/dbt_tas_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:635: src/CMakeFiles/dbt_tas_unittest.dir/all] Error 2
[ 98%] Linking CXX executable ../bin/cp2k.ssmp
icpx: warning: use of '-qopenmp' recommended over '-fopenmp' [-Wrecommended-option]
[ 99%] Linking CXX executable ../bin/xyz2dcd.ssmp
[ 99%] Linking CXX executable ../bin/graph.ssmp
icpx: warning: use of '-qopenmp' recommended over '-fopenmp' [-Wrecommended-option]
icpx: warning: use of '-qopenmp' recommended over '-fopenmp' [-Wrecommended-option]
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/cp2k-bin.dir/build.make:125: bin/cp2k.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:315: src/CMakeFiles/cp2k-bin.dir/all] Error 2
[ 99%] Linking CXX executable ../bin/dumpdcd.ssmp
icpx: warning: use of '-qopenmp' recommended over '-fopenmp' [-Wrecommended-option]
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/graph.dir/build.make:125: bin/graph.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:443: src/CMakeFiles/graph.dir/all] Error 2
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/xyz2dcd.dir/build.make:125: bin/xyz2dcd.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:507: src/CMakeFiles/xyz2dcd.dir/all] Error 2
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/dumpdcd.dir/build.make:125: bin/dumpdcd.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:475: src/CMakeFiles/dumpdcd.dir/all] Error 2
[100%] Linking CXX executable ../bin/dbt_unittest.ssmp
icpx: warning: use of '-qopenmp' recommended over '-fopenmp' [-Wrecommended-option]
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
icpx: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/dbt_unittest.dir/build.make:125: bin/dbt_unittest.ssmp] Error 1
make[1]: *** [CMakeFiles/Makefile2:603: src/CMakeFiles/dbt_unittest.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
请问老师知道如何解决吗,谢谢了
作者
Author:
UW_0728.    时间: 2026-1-16 19:13
本帖最后由 UW_0728. 于 2026-1-17 02:33 编辑

1. 检查一下tblite有没有正确安装,没装tblite的话第一个命令加上-DCP2K_USE_TBLITE=OFF试试看(这个问题其实查CMakeLists.txt就知道问题所在了)(顺带一提,个人不是很推崇在-DCP2K_USE_EVERYTHING=ON基础上加-DCP2K_USE_xxx=OFF的做法,因为CP2K未来支持或需要库和依赖可能会越来越多,这样做很容易导致漏掉某个未安装的依赖从而cmake阶段报错;我认为还是根据自己toolchain中装/找的依赖手动加-DCP2K_USE_xxx=ON最为稳妥)
2. toolchain编译时用的什么编译器,make install时就用什么编译器,绝对不要混用;更何况CP2K目前对新的oneAPI的支持(尤其是ifx)不完善

P.S. 你的第二步指令没有-DCP2K_USE_EVERYTHING=ON,所以加那么一堆-DCP2K_USE_xxx=OFF没意义,而-DCP2K_USE_xxx=ON也没加几个,相当于编译时没利用上toolchain里装的大部分依赖。

作者
Author:
dahai7719    时间: 2026-1-17 08:55
3. 运行构建指令的时候出错,倒腾了半天还没解决,求帮助:CMake Error at CMakeLists.txt:768 (find_package):
  By not providing "Finddftd4.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "dftd4", but
  CMake did not find one.

  Could not find a package configuration file provided by "dftd4" with any of
  the following names:

    dftd4Config.cmake
    dftd4-config.cmake

  Add the installation prefix of "dftd4" to CMAKE_PREFIX_PATH or set
  "dftd4_DIR" to a directory containing one of the above files.  If "dftd4"
  provides a separate development package or SDK, be sure it has been
  installed.
作者
Author:
UW_0728.    时间: 2026-1-17 17:45
dahai7719 发表于 2026-1-17 08:55
3. 运行构建指令的时候出错,倒腾了半天还没解决,求帮助:CMake Error at CMakeLists.txt:768 (find_packa ...

toolchain安装DFT-D4或tblite了吗,如果安装了的话,执行source {/path/to/cp2k}/tools/toolchain/install/setup那一步了吗
作者
Author:
dahai7719    时间: 2026-1-18 09:19
UW_0728. 发表于 2026-1-17 17:45
toolchain安装DFT-D4或tblite了吗,如果安装了的话,执行source {/path/to/cp2k}/tools/toolchain/instal ...

都安装了,dftd4-3.7.0,tblite-0.5.0,也显示安装成功了(toolchain/install下面各自的安装包下面都有install=successful的文件) ,也source了,但是就是不行

作者
Author:
UW_0728.    时间: 2026-1-18 13:02
dahai7719 发表于 2026-1-18 09:19
都安装了,dftd4-3.7.0,tblite-0.5.0,也显示安装成功了(toolchain/install下面各自的安装包下面都有inst ...

这是怎么两个都装上的,我记得如果装tblite的话会自动取消安装dftd4,因为tblite包含了dftd4;如果强制性地都安装了的话是不是有可能冲突了?
作者
Author:
Biubiubiu123    时间: 2026-1-18 22:05
本帖最后由 Biubiubiu123 于 2026-1-18 22:22 编辑

前辈好,ubuntu 24.04.3 cmake 中报错,没有生成可执行文件
source /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/setup
cd /home/gh/cp2k/cp2k-2026.1
mkdir build
cd build
cmake -S .. -DCP2K_USE_EVERYTHING=ON -DCP2K_USE_DLAF=OFF -DCP2K_USE_PEXSI=OFF -DCP2K_USE_LIBSMEAGOL=OFF -DCP2K_USE_DEEPMD=OFF -DCP2K_USE_ACE=OFF -DCP2K_USE_TREXIO=OFF -DCP2K_USE_GREENX=OFF -DCP2K_USE_LIBTORCH=OFF -DCP2K_USE_MIMIC=OFF -DCMAKE_INSTALL_PREFIX=/home/gh/cp2k/cp2k-2026.1/exe/ -DCP2K_DATA_DIR=/home/gh/cp2k/cp2k-2026.1/data
make install -j40

log信息
[ 52%] Linking CXX shared library libcp2k.so
[ 98%] Built target cp2k
[ 98%] Building Fortran object src/CMakeFiles/gemm_square_unittest.dir/common/gemm_square_unittest.F.o
[ 98%] Building Fortran object src/CMakeFiles/parallel_rng_types_unittest.dir/common/parallel_rng_types_unittest.F.o
[ 98%] Building Fortran object src/CMakeFiles/cp2k-bin.dir/start/cp2k.F.o
[ 98%] Building Fortran object src/CMakeFiles/memory_utilities_unittest.dir/common/memory_utilities_unittest.F.o
[ 98%] Building Fortran object src/CMakeFiles/graph.dir/metadyn_tools/graph.F.o
[ 98%] Building Fortran object src/CMakeFiles/xyz2dcd.dir/motion/xyz2dcd.F.o
[ 98%] Building Fortran object src/CMakeFiles/dbt_unittest.dir/dbt/dbt_unittest.F.o
[ 98%] Building Fortran object src/CMakeFiles/dumpdcd.dir/motion/dumpdcd.F.o
[ 98%] Building C object src/CMakeFiles/libcp2k_unittest.dir/start/libcp2k_unittest.c.o
[ 98%] Building Fortran object src/CMakeFiles/nequip_unittest.dir/nequip_unittest.F.o
[ 98%] Building Fortran object src/CMakeFiles/gx_ac_unittest.dir/gx_ac_unittest.F.o
[ 98%] Building Fortran object src/CMakeFiles/dbt_tas_unittest.dir/dbt/tas/dbt_tas_unittest.F.o
[ 98%] Linking CXX executable ../bin/gx_ac_unittest.psmp
[ 98%] Linking CXX executable ../bin/libcp2k_unittest.psmp
[ 98%] Linking CXX executable ../bin/gemm_square_unittest.psmp
[ 98%] Linking CXX executable ../bin/memory_utilities_unittest.psmp
[ 98%] Linking CXX executable ../bin/parallel_rng_types_unittest.psmp
[ 98%] Linking CXX executable ../bin/nequip_unittest.psmp
[ 98%] Linking CXX executable ../bin/dbt_tas_unittest.psmp
...
...
...

collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/graph.dir/build.make:136:bin/graph.psmp] 错误 1
make[1]: *** [CMakeFiles/Makefile2:443:src/CMakeFiles/graph.dir/all] 错误 2
make: *** [Makefile:136:all] 错误 2


作者
Author:
UW_0728.    时间: 2026-1-18 22:36
Biubiubiu123 发表于 2026-1-18 22:05
前辈好,ubuntu 24.04.3 cmake 中报错,没有生成可执行文件
source /home/gh/cp2k/cp2k-2026.1/tools/tool ...

关键的那几行报错原因你恰好给省略掉了……
作者
Author:
Biubiubiu123    时间: 2026-1-18 22:43
UW_0728. 发表于 2026-1-18 22:36
关键的那几行报错原因你恰好给省略掉了……

sorrysorry,再帮忙看下,我以为就中间不重要的
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_f2c'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Alltoallw_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_ack_failed'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_failure_ack'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Exscan_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_agree'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so: undefined reference to `gotoblas'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Scatterv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_nth_pset'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_allgather_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_errhandler'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_alltoallv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Alltoall_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Status_f082f'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Psend_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Precv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Bcast_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_revoke'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Allreduce_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Allgather_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_is_revoked'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_alltoall_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Isendrecv'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Group_from_session_pset'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Info_create_env'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_pset_info'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Gather_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_finalize'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_set_errhandler'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `ompi_instance_count'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_iagree'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Reduce_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Comm_create_from_group'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Comm_idup_with_info'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Reduce_scatter_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Scan_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Barrier_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Parrived'
collect2: error: ld returned 1 exit status
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Pready_list'
make[2]: *** [src/CMakeFiles/graph.dir/build.make:136:bin/graph.psmp] 错误 1
make[1]: *** [CMakeFiles/Makefile2:443:src/CMakeFiles/graph.dir/all] 错误 2
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_shrink'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_failure_get_acked'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_allgatherv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_alltoallw_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Isendrecv_replace'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Status_f2f08'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_num_psets'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Alltoallv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Pready'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Intercomm_create_from_groups'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Scatter_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_call_errhandler'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_get_failed'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Reduce_scatter_block_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Gatherv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Allgatherv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Pready_range'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_c2f'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_info'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_f2c'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Alltoallw_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_ack_failed'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_failure_ack'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Exscan_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_agree'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so: undefined reference to `gotoblas'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Scatterv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_nth_pset'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_allgather_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_errhandler'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_alltoallv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Alltoall_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Status_f082f'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Psend_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Precv_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Bcast_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_revoke'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Allreduce_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Allgather_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_is_revoked'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Neighbor_alltoall_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Isendrecv'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Group_from_session_pset'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Info_create_env'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_get_pset_info'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Gather_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_finalize'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Session_set_errhandler'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `ompi_instance_count'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPIX_Comm_iagree'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Reduce_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Comm_create_from_group'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Comm_idup_with_info'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Reduce_scatter_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Scan_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Barrier_init'
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9/lib/libmpi_mpifh.so: undefined reference to `PMPI_Parrived'
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/dbt_unittest.dir/build.make:136:bin/dbt_unittest.psmp] 错误 1
make[1]: *** [CMakeFiles/Makefile2:603:src/CMakeFiles/dbt_unittest.dir/all] 错误 2
make: *** [Makefile:136:all] 错误 2

作者
Author:
UW_0728.    时间: 2026-1-18 23:01
Biubiubiu123 发表于 2026-1-18 22:43
sorrysorry,再帮忙看下,我以为就中间不重要的
/usr/bin/ld: /home/gh/cp2k/cp2k-2026.1/tools/toolcha ...

应该是toolchain编译或者程序编译环节出了问题,说清楚编译环境,以及编译cp2k时用的编译器是否和编译toolchain工具集时的一致
作者
Author:
dahai7719    时间: 2026-1-19 07:54
UW_0728. 发表于 2026-1-18 13:02
这是怎么两个都装上的,我记得如果装tblite的话会自动取消安装dftd4,因为tblite包含了dftd4;如果强制性 ...

因为用tootchain安装后(--with-dftd4=install),到了Cmake的时候会出现同样的出错问题,找不到dftd4的安装包,在install文件夹下也找不到,于是我用了(--with-dftd4没有加=install)重新toolchain了一遍之后Install里面就出现了dftd4-3.7.0, 但是source 过后cmake 还是出现了同样的问题,因此不知道是怎么回事?

作者
Author:
Biubiubiu123    时间: 2026-1-19 17:32
本帖最后由 Biubiubiu123 于 2026-1-19 17:42 编辑
UW_0728. 发表于 2026-1-18 23:01
应该是toolchain编译或者程序编译环节出了问题,说清楚编译环境,以及编译cp2k时用的编译器是否和编译too ...

电脑装过orca,是不是因为有两个openmpi。
Compiling with 10 processes for target native.
==================== Finding GCC from system paths ====================
path to gcc is /usr/bin/gcc
path to g++ is /usr/bin/g++
path to gfortran is /usr/bin/gfortran
GCC compiler version 13.3.0 found
Found include directory /usr/include
Found lib directory /usr/lib/x86_64-linux-gnu
Step gcc took 0.00 seconds.
Step intel took 0.00 seconds.
Step amd took 0.00 seconds.
==================== Getting proc arch info using OpenBLAS tools ====================
wget  --quiet https://www.cp2k.org/static/downloads/OpenBLAS-0.3.30.tar.gz -O OpenBLAS-0.3.30.tar.gz
OpenBLAS-0.3.30.tar.gz: 成功
Checksum of OpenBLAS-0.3.30.tar.gz Ok
OpenBLAS detected LIBCORE = zen
OpenBLAS detected ARCH    = x86_64
==================== Installing CMake ====================
wget  --quiet https://www.cp2k.org/static/down ... 1.7-linux-x86_64.sh -O cmake-3.31.7-linux-x86_64.sh
cmake-3.31.7-linux-x86_64.sh: 成功
Checksum of cmake-3.31.7-linux-x86_64.sh Ok
Installing from scratch into /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/cmake-3.31.7
Step cmake took 21.00 seconds.
==================== Installing Ninja  ====================
wget  --quiet https://www.cp2k.org/static/downloads/ninja-v1.13.1.tar.gz -O ninja-v1.13.1.tar.gz
ninja-v1.13.1.tar.gz: 成功
Checksum of ninja-v1.13.1.tar.gz Ok
Installing from scratch into /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/ninja-v1.13.1
Step ninja took 10.00 seconds.
==================== Installing OpenMPI ====================
wget  --quiet https://www.cp2k.org/static/downloads/openmpi-5.0.9.tar.bz2 -O openmpi-5.0.9.tar.bz2
openmpi-5.0.9.tar.bz2: 成功
Checksum of openmpi-5.0.9.tar.bz2 Ok
Installing from scratch into /home/gh/cp2k/cp2k-2026.1/tools/toolchain/install/openmpi-5.0.9


作者
Author:
乐平    时间: 2026-1-19 17:59
UW_0728. 发表于 2026-1-7 23:08
我看了下2026.1的toolchain脚本,发现默认选项为with_hdf5="__DONTUSE__",即默认不安装HDF5。把cmake ...

这个问题在两周前 CP2K 的 Github 上也有人提出来了,但是开发者到现在并没有回应……
https://github.com/cp2k/cp2k/issues/4674
作者
Author:
乐平    时间: 2026-1-19 18:00
Qilin 发表于 2026-1-13 15:41
把下面三行直接写入 `~/.bashrc` 会把初学者拐带坏的。再不济也应该写入 `~/env/cp2k_2026.1.env`。
```
...

这不能怪作者,是 Sob 带出来的
作者
Author:
乐平    时间: 2026-1-19 18:06
本帖最后由 乐平 于 2026-1-19 18:07 编辑

正式编译 cp2k 之前的各种库的编译还是老样子,后面正式编译 cp2k 才换成了 cmake

cmake 编译模式并没有“报错概率更低一点” ……

CP2K 开发者们一贯的简陋手册是罪恶之源……
官网手册编译的例子 https://manual.cp2k.org/trunk/ge ... source.html#example  

  1. cd <CP2K_REPOSITORY>
  2. mkdir build/
  3. cmake -S . -B build \
  4.     -GNinja \
  5.     -DCP2K_USE_LIBXC=ON \
  6.     -DCP2K_USE_LIBINT2=ON \
  7.     -DCP2K_USE_SPGLIB=ON \
  8.     -DCP2K_USE_ELPA=ON \
  9.     -DCP2K_USE_SPLA=ON \
  10.     -DCP2K_USE_SIRIUS=ON \
  11.     -DCP2K_USE_COSMA=ON \
  12.     -DCP2K_USE_ACCEL=CUDA -DCP2K_WITH_GPU=A100

  13. cmake --build build -j 32
复制代码


第一个选项 -GNinja 至少在我这里是没法正常编译的,已经给 CP2K 的 Github 提了 issue
https://github.com/cp2k/cp2k/issues/4705

去掉 -GNinja 选项之后,Spglib 又报错说 Component omp of Spglib: NOT FOUND
之前 make 的时代是从来没有这种报错的……
作者
Author:
UW_0728.    时间: 2026-1-19 19:35
本帖最后由 UW_0728. 于 2026-1-19 19:46 编辑
乐平 发表于 2026-1-19 18:06
正式编译 cp2k 之前的各种库的编译还是老样子,后面正式编译 cp2k 才换成了 cmake

cmake 编译模式并没 ...

我没出过这样的问题
手册里那个应该是带GPU加速的,对我来说没意义
带个-G Ninja也不知道用处在哪儿

作者
Author:
UW_0728.    时间: 2026-1-19 19:37
Biubiubiu123 发表于 2026-1-19 17:32
电脑装过orca,是不是因为有两个openmpi。
Compiling with 10 processes for target native.
========= ...

应该是。你如果之前有OpenMPI的话直接--with-openmpi=system就可以了,否则可能会起冲突。鉴于你这也不知道是用哪套编译出来的,不行就把install文件夹删了,加上上面说的选项从头开始吧
作者
Author:
UW_0728.    时间: 2026-1-19 19:54
Qilin 发表于 2026-1-13 15:41
把下面三行直接写入 `~/.bashrc` 会把初学者拐带坏的。再不济也应该写入 `~/env/cp2k_2026.1.env`。
```
...

单另写个环境变量文件多此一举,我又没有区分不同环境的需要,需要区分不同环境的应该也不是初学者水平了,要么就是计算集群
在自己的个人电脑上开root用户完全可行,没有权限限制,畅行无阻,我也没有因为用root把系统搞不对劲过
作者
Author:
UW_0728.    时间: 2026-1-19 19:56
dahai7719 发表于 2026-1-19 07:54
因为用tootchain安装后(--with-dftd4=install),到了Cmake的时候会出现同样的出错问题,找不到dftd4的安 ...

加--with-dftd4和--with-dftd4=install没有区别。有可能你toolchain一步没弄成功就急着编译CP2K了,注意运行toolchain脚本安装依赖过程中的提示
作者
Author:
乐平    时间: 2026-1-19 22:20
UW_0728. 发表于 2026-1-19 19:35
我没出过这样的问题
手册里那个应该是带GPU加速的,对我来说没意义
带个-G Ninja也不知道用处在哪儿

跟 GPU 没有任何关系……

如果你在 cp2k 的路径下进入 cmake 目录,里面有 cmake_cp2k.sh 文件,打开它就能看到
  1. elif [[ "${PROFILE}" == "toolchain" ]] && [[ "${VERSION}" == "psmp" ]]; then
  2.   # TODO Re-enable SIRIUS once performance regression of COSMA is fixed:
  3.   # https://github.com/cp2k/cp2k/issues/4663
  4.   cmake \
  5.     -GNinja \
  6.     -DCMAKE_INSTALL_PREFIX="${INSTALL_PREFIX}" \
  7.     -DCP2K_USE_EVERYTHING=ON \
  8.     -DCP2K_USE_DLAF=OFF \
  9.     -DCP2K_USE_PEXSI=OFF \
  10.     -DCP2K_USE_SIRIUS=OFF \
  11.     -Werror=dev \
  12.     .. |& tee ./cmake.log
  13.   CMAKE_EXIT_CODE=$?
复制代码

作者
Author:
UW_0728.    时间: 2026-1-20 11:26
本帖最后由 UW_0728. 于 2026-1-20 11:33 编辑
乐平 发表于 2026-1-19 22:20
跟 GPU 没有任何关系……

如果你在 cp2k 的路径下进入 cmake 目录,里面有 cmake_cp2k.sh 文件,打开 ...

那个Issue有回复了
顺带一提,如果cmake环节出错而重新构建时,cmake默认会在考虑新构建选项的同时从失败的地方继续(类似于新的选项在一定程度上是叠加而非完全覆盖?),因此为保险起见一定要先清空build目录下产生的所有文件(rm -rf *)再执行cmake,以免和残留的缓存文件起冲突;我根据那个回复合理怀疑你没有删旧的缓存文件直接重新cmake导致的出错
作者
Author:
乐平    时间: 2026-1-21 12:07
本帖最后由 乐平 于 2026-1-21 12:18 编辑
UW_0728. 发表于 2026-1-20 11:26
那个Issue有回复了
顺带一提,如果cmake环节出错而重新构建时,cmake默认会在考虑新构建选项的同时从失 ...

谢谢讨论
感觉 CP2K 用来 cmake 之后把编译弄得更复杂了。
从 issue 里反馈的信息来看,需要根据报错把该补上的参数都补上,而参数均来自下面的链接里各个库
https://manual.cp2k.org/trunk/technologies/libraries.html

根据上面的链接,将所有没有在 toolchain 里预先安装的库都需要 OFF 掉。

我预先编译的库有
  1. ./install_cp2k_toolchain.sh --with-mkl=system --with-gcc=system --with-openmpi=install --with-plumed=install --with-tblite=install --with-hdf5=install
复制代码



我的 cmake 命令是
  1. cmake -S . -B build -DCP2K_USE_MPI=ON -DCP2K_USE_FFTW3=ON -DCP2K_USE_LIBINT2=ON -DCP2K_USE_LIBXC=ON -DCP2K_USE_SPGLIB=ON -DCP2K_USE_VORI=ON -DCP2K_USE_COSMA=ON -DCP2K_USE_ELPA=ON -DCP2K_USE_LIBXSMM=ON -DCP2K_USE_PLUMED=ON -DCP2K_USE_SIRIUS=ON -DCP2K_USE_LIBVDWXC=ON -DCP2K_USE_SIRIUS_DFTD4=ON -DCP2K_USE_DFTD4=ON -DCP2K_USE_TBLITE=ON -DCP2K_USE_HDF5=ON -DCP2K_USE_LIBSMEAGOL=OFF -DCP2K_USE_DEEPMD=OFF -DCP2K_USE_ACE=OFF -DCP2K_USE_LIBTORCH=OFF -DCP2K_USE_MIMIC=OFF -DCP2K_USE_TREXIO=OFF -DCP2K_USE_GREENX=OFF
复制代码



也就是说,需要把没有预先安装的 libsmeagol, DeePMD, ACE, LibTorch, MIMIC,TREXIO, GreenX 这些库都 OFF (命令中最后 7 个)
  1. -DCP2K_USE_LIBSMEAGOL=OFF -DCP2K_USE_DEEPMD=OFF -DCP2K_USE_ACE=OFF -DCP2K_USE_LIBTORCH=OFF -DCP2K_USE_MIMIC=OFF -DCP2K_USE_TREXIO=OFF -DCP2K_USE_GREENX=OFF
复制代码


另外,我没有指定 -DCMAKE_INSTALL_PREFIX= 参数,编译之后 CP2K 可执行程序放在 ~/cp2k-2026.01/build/bin 目录下了。而不是您说的 /usr/local 目录下。



作者
Author:
UW_0728.    时间: 2026-1-21 16:02
本帖最后由 UW_0728. 于 2026-1-21 16:03 编辑
乐平 发表于 2026-1-21 12:07
谢谢讨论
感觉 CP2K 用来 cmake 之后把编译弄得更复杂了。
从 issue 里反馈的信息来看,需要根据报错把 ...
另外,我没有指定 -DCMAKE_INSTALL_PREFIX= 参数,编译之后 CP2K 可执行程序放在 ~/cp2k-2026.01/build/bin 目录下了。而不是您说的 /usr/local 目录下。
这里指的是install之后的路径,而非编译后未安装时的路径。

将所有没有在 toolchain 里预先安装的库都需要 OFF 掉。
我没加那些OFF的选项,但也没出任何问题
作者
Author:
乐平    时间: 2026-1-21 16:08
本帖最后由 乐平 于 2026-1-21 16:30 编辑
UW_0728. 发表于 2026-1-21 16:02
这里指的是install之后的路径,而非编译后未安装时的路径。

我没加那些OFF的选项,但也没出任何问题

并不是 “而非编译后未安装时的路径”

cmake --build build -j 32

之后,在 ~/cp2k-2026.01/build/bin 目录下就是

  1. cp2k.psmp              dbt_unittest.psmp          graph.psmp          gx_ac_unittest.psmp             nequip_unittest.psmp
  2. dbm_miniapp.psmp       dumpdcd.psmp               grid_miniapp.psmp   libcp2k_unittest.psmp           parallel_rng_types_unittest.psmp
  3. dbt_tas_unittest.psmp  gemm_square_unittest.psmp  grid_unittest.psmp  memory_utilities_unittest.psmp  xyz2dcd.psmp
复制代码



另外,我发现您最后编译用的是 make install -jN, 而不是您标题里说的 cmake


而 CP2K-2026.01 推荐的 cmake 是
  1. ========================== usage =========================
  2. Done!
  3. To use the installed tools and libraries and cp2k version
  4. compiled with it you will first need to execute at the prompt:
  5.   source /public/apps/cp2k/202601/tools/toolchain/install/setup

  6. If you invoked the toolchain with --install-all then you can proceed to build cp2k like this:
  7.   cd cp2k/
  8.   cmake -S . -B build -DCP2K_USE_EVERYTHING=ON -DCP2K_USE_DLAF=OFF -DCP2K_USE_PEXSI=OFF
  9.   cmake --build build -j 32

  10. If you installed only some packages then you'll have to assemble the matching cmake command yourself.
  11. For available build options see: https://manual.cp2k.org/trunk/getting-started/build-from-source.html
复制代码


您最终稿的编译跟您前面写的一大段完全背道而驰了……


作者
Author:
UW_0728.    时间: 2026-1-21 17:01
本帖最后由 UW_0728. 于 2026-1-21 17:12 编辑
乐平 发表于 2026-1-21 16:08
并不是 “而非编译后未安装时的路径”

cmake --build build -j 32

"cmake --build build -j N"后其实还有一步"cmake --install build",执行了这一步带"--install"的指令才会安装到${CMAKE_INSTALL_PREFIX}所指的地方,只是这个指令CP2K手册里没有提及而已(附:cmake --install指令无法也无需带-j)。多做一步install是为了编译和安装后(如果硬盘空间吃紧)可以直接把build目录删除掉(或者不删掉但执行make clean),能节省出1GB左右的空间。
另外注意cmake执行后build目录里是生成了Makefile的(但是显然不是之前的GNU Makefile的格式),因此make指令完全可以用,切到build目录下(cd build)就可以用了;在此情况下,"make -j N"等价于"cmake --build . -j N";"make install -j N"等价于"cmake --build . -j N && cmake --install ."。

作者
Author:
kogareru1z    时间: 2026-1-22 10:25
请问各位有遇到cp2k2026.1版的性能问题吗?我发现对于同一个任务同样的设置,最新版的scf从第二步开始的耗时是2025.2版的4倍以上,参考的是sob老师的教程且我自己也编译了mkl版,结果都是一样,很不解
作者
Author:
UW_0728.    时间: 2026-1-22 12:43
kogareru1z 发表于 2026-1-22 10:25
请问各位有遇到cp2k2026.1版的性能问题吗?我发现对于同一个任务同样的设置,最新版的scf从第二步开始的耗 ...

没遇到。输入文件发来我再测一测
作者
Author:
kogareru1z    时间: 2026-1-22 13:25
UW_0728. 发表于 2026-1-22 12:43
没遇到。输入文件发来我再测一测

这是输入文件

作者
Author:
UW_0728.    时间: 2026-1-22 15:48
本帖最后由 UW_0728. 于 2026-1-22 15:51 编辑
kogareru1z 发表于 2026-1-22 13:25
这是输入文件

我简单试了下,没有这样的问题:(我看到你发的另一个帖子里面带的输出显示了)
  1. SCF WAVEFUNCTION OPTIMIZATION

  2.   Step     Update method      Time    Convergence         Total energy    Change
  3.   ------------------------------------------------------------------------------
  4.      1 NoMix/Diag. 0.40E+00   32.6     0.70457347    -38566.0388841912 -3.86E+04
  5.      2 Broy./Diag. 0.40E+00   38.6     1.56786457    -38770.3746255539 -2.04E+02
  6.      3 Broy./Diag. 0.40E+00   38.2     1.34567754    -38569.9193082223  2.00E+02
复制代码
怀疑是你编译或者编译环境的问题
作者
Author:
kogareru1z    时间: 2026-1-22 16:49
UW_0728. 发表于 2026-1-22 15:48
我简单试了下,没有这样的问题:(我看到你发的另一个帖子里面带的输出显示了)
怀疑是你编译或者编译环 ...


太奇怪了,我重启电脑又在另一个目录进行测试,发现当我添加LEVEL_SHIFT 0.5关键词后,计算耗时就大幅增加,很诡异

作者
Author:
UW_0728.    时间: 2026-1-22 16:50
kogareru1z 发表于 2026-1-22 16:49
太奇怪了,我重启电脑又在另一个目录进行测试,发现当我添加LEVEL_SHIFT 0.5关键词后,计算耗时就大幅 ...

应该是编译问题,能级移动设置不应该显著影响SCF计算速度
作者
Author:
UW_0728.    时间: 2026-1-26 21:12
https://github.com/cp2k/cp2k/com ... 80b7019669123e3b5ce

CP2K目前的开发分支已经实现在toolchain结束时自动生成相应的cmake选项了,因此在原文中补充了这一点。
作者
Author:
HNUST    时间: 2026-2-21 18:12
elpa,HDF5总是出错,哎真是服了,关闭以后,cmake的时候又跳出来报错。我甚至把系统带的cmake都删了,全都让脚本来安装,但是elpa跟hdf5就是报错
作者
Author:
UW_0728.    时间: 2026-2-21 18:21
HNUST 发表于 2026-2-21 18:12
elpa,HDF5总是出错,哎真是服了,关闭以后,cmake的时候又跳出来报错。我甚至把系统带的cmake都删了,全都 ...

先看:
在网上求助计算化学问题的时候必须把问题描述得详细、具体、准确、清楚
http://sobereva.com/620http://bbs.keinsci.com/thread-25787-1-1.html

1. ELPA和HDF5在安装时报错的原因是什么?最好仔细查看并附上相应的日志文件。
2. 你的cmake指令是什么?
作者
Author:
HNUST    时间: 2026-2-21 23:00
UW_0728. 发表于 2026-2-21 18:21
先看:
在网上求助计算化学问题的时候必须把问题描述得详细、具体、准确、清楚
http://sobereva.com/62 ...

已经搞定了,我把自己的cmake、openmpi、fftw、mkl之类的bashrc全注释掉才行。虽然我的版本跟cp2k要求的基本一样,但是就是不行。报错基本与cmake、gfortran有关,高了半天没搞定,哎,注释完以后,一点问题都没有,一遍过
作者
Author:
Uus/pMeC6H4-/キ    时间: 2026-3-11 12:31
我想问个小问题。上周PR #4865在更新toolchain里的libint到2.13.1版的同时也新增了系统包管理器安装boost和eigen3依赖的要求,这点也在您的博文里提到了。若在Rocky Linux 10.1用dnf,那应该从哪个repo或者channel找eigen3-devel呢?我现在无法直接找到eigen3-devel,搜eigen的唯一结果也似乎不对:
  1. $ dnf repolist
  2. repo id                                             repo name
  3. appstream                                           Rocky Linux 10 - AppStream
  4. baseos                                              Rocky Linux 10 - BaseOS
  5. epel                                                Extra Packages for Enterprise Linux 10 - x86_64
  6. extras                                              Rocky Linux 10 - Extras
  7. $ dnf search eigen3-devel
  8. Last metadata expiration check: 18:47:56 ago on Tue 10 Mar 2026 05:30:42 PM CST.
  9. No matches found.
  10. $ dnf search eigen
  11. ========================================================== Summary Matched: eigen ===========================================================
  12. arpack.x86_64 : Fortran 77 subroutines for solving large scale eigenvalue problems
  13. $
复制代码

作者
Author:
abin    时间: 2026-3-11 13:15
Uus/pMeC6H4-/キ 发表于 2026-3-11 12:31
我想问个小问题。上周PR #4865在更新toolchain里的libint到2.13.1版的同时也新增了系统包管理器安装boost和 ...

Enable repo, crb.
作者
Author:
UW_0728.    时间: 2026-3-11 14:54
本帖最后由 UW_0728. 于 2026-3-11 15:00 编辑
Uus/pMeC6H4-/キ 发表于 2026-3-11 12:31
我想问个小问题。上周PR #4865在更新toolchain里的libint到2.13.1版的同时也新增了系统包管理器安装boost和 ...

dnf config-manager --set-enabled crb

这个建议随同EPEL一起默认开启,用处不小(而且我记得安装epel-release后默认就会附带启用crb的建议和指令)

作者
Author:
Uus/pMeC6H4-/キ    时间: 2026-3-27 00:48
现行的 CMake 系统如何同时构建动态库链接的 libcp2k.so 和静态库链接的 libcp2k.a 呢?我的猜想是在跑完 toolchain 以后到 CP2K 主目录下分几步执行:
  1. # shared library libcp2k.so
  2. cmake -S . -B ./build-shared -DCMAKE_INSTALL_PREFIX=./install-shared {...other cmake options...}
  3. cmake --build build-shared --target install -j
  4. # static library libcp2k.a
  5. cmake -S . -B ./build-static -DCMAKE_INSTALL_PREFIX=./install-static -DBUILD_SHARED_LIBS=OFF {...other cmake options...}
  6. cmake --build build-static --target install -j
复制代码

目前的 generate_cmake_options.sh 生成的 $CP2K_CMAKE_OPTIONS 包括了 -DCMAKE_INSTALL_PREFIX=./install 选项,但我不确定两次都用同一个 install 的目录会不会冲突,所以才有这个问题。最好能在自动生成的安装指南里讲清楚这点。

(顺便,安装/链接了 Ninja 后编译选项里是否启用 -GNinja 带来的 makefile 的区别也应该有解释。)
作者
Author:
UW_0728.    时间: 2026-3-27 05:37
Uus/pMeC6H4-/キ 发表于 2026-3-27 00:48
现行的 CMake 系统如何同时构建动态库链接的 libcp2k.so 和静态库链接的 libcp2k.a 呢?我的猜想是在跑完 t ...

1. 是的,动态库和静态库不能同时构建。最好是分两个构建目录,不过即使在相同build目录也不会导致冲突,只是会把之前的BUILD_SHARED_LIBS选项设置覆盖掉而已;install目录应该分开,否则后面构建的会把前面构建的完全覆盖掉,达不成“同时构建动态库链接的 libcp2k.so 和静态库链接的 libcp2k.a”的目的(虽然我也不知道这个意义在哪里)。
2. cmake --build 指令是属于CMake自己的,对于任何generator生成的构建文件都适用,在构建阶段用了-G Ninja只是意味着不能直接在build目录下直接用make/gmake指令了,这两个生成器生成的东西除了组织架构上也没啥区别。
作者
Author:
Uus/pMeC6H4-/キ    时间: 2026-3-27 10:16
UW_0728. 发表于 2026-3-27 05:37
1. 是的,动态库和静态库不能同时构建。最好是分两个构建目录,不过即使在相同build目录也不会导致冲突, ...

1. 同时有用 CP2K 本身跑单独的 DFT 任务(所以需要 libcp2k.so )和链接 GROMACS 跑 QM/MM 任务(所以需要 libcp2k.a)的需求是什么很奇怪的事情吗?当然如果 libcp2k.a 的版本也能像 libcp2k.so 的版本那样直接跑是更好的,可以省一次编译,但是我不知道是不是真能这样。我觉得您可以开 PR 把这个问题在 generate_cmake_options.sh 末尾生成的安装指南里说说。
2. 基于 Spack 的 make_cp2k.sh 的 CMake 指令默认都要用 -GNinja 这点,应当在 make_cp2k.sh 的帮助语句或者注释里说明缘故。目前在 toolchain 里面并没有哪个依赖库是只有 CMake 及 GNU Make 就不能编译、必须要使用 CMake 带 Ninja 的,哪怕官网号称要求 Ninja 的 tblite 也是,之前我测试 tblite 离线安装时没用 Ninja 也照样能编译通过、获得二进制可执行文件。
作者
Author:
UW_0728.    时间: 2026-3-27 10:35
本帖最后由 UW_0728. 于 2026-3-27 10:38 编辑
Uus/pMeC6H4-/キ 发表于 2026-3-27 10:16
1. 同时有用 CP2K 本身跑单独的 DFT 任务(所以需要 libcp2k.so )和链接 GROMACS 跑 QM/MM 任务(所以需 ...

直接全用静态版(链接.a的)就可以吧,不应该有问题。当然,我会在说明中补充静态链接这一点(尽管我觉得直接在手册中相应部分补充说明会更好)。
Ninja我计划将来如果要砍toolchain的话会把它砍掉,因为它当时被加进去的唯一原因就是dftd4“需要”ninja,但现在看来实际上根本用不到。至于为什么在Spack里面专门要用-G Ninja,我也不清楚。
作者
Author:
Uus/pMeC6H4-/キ    时间: 2026-3-31 10:44
UW_0728. 发表于 2026-3-27 05:37
1. 是的,动态库和静态库不能同时构建。最好是分两个构建目录,不过即使在相同build目录也不会导致冲突, ...

cmake里面install目录具体是以-DCMAKE_INSTALL_PREFIX选项为准,还是以--target install设置的为准,特别是二者不同的情况下?
cmake --build build --target install(目前开发版本推荐的指令)和cmake --install install有什么区别?
作者
Author:
UW_0728.    时间: 2026-3-31 11:02
本帖最后由 UW_0728. 于 2026-3-31 11:07 编辑

对于同一个构建流程,--target install安装到的地方就是CMAKE_INSTALL_PREFIX设置的地方,两者毫无区别,所以要换install目录要么重运行一遍cmake(但是接下来应该不会再经历后面长时间的编译流程,而是只影响安装部分,因为只有CMAKE_INSTALL_PREFIX这一个选项被覆盖了),要么临时设置新的环境变量,比如运行"CMAKE_INSTALL_PREFIX=./install cmake --install build"(纠正:这里不应该跟install,而是build,从构建目录安装)。

"cmake --build build --target install"相当于是"cmake --build build"和"cmake --install build"合二为一;后者只是把构建好的东西安装在指定目录下,无法执行build操作。这与"make install"的情况确实不同,"make install"在cmake下严格等价于"cmake --build . --target install",同理"make clean"就是"cmake --build . --target clean"。
作者
Author:
UW_0728.    时间: 2026-3-31 11:07
Uus/pMeC6H4-/キ 发表于 2026-3-31 10:44
cmake里面install目录具体是以-DCMAKE_INSTALL_PREFIX选项为准,还是以--target install设置的为准,特别 ...

对于同一个构建流程,--target install安装到的地方就是CMAKE_INSTALL_PREFIX设置的地方,两者毫无区别,所以要换install目录要么重运行一遍cmake(但是接下来应该不会再经历后面长时间的编译流程,而是只影响安装部分,因为只有CMAKE_INSTALL_PREFIX这一个选项被覆盖了),要么临时设置新的环境变量,比如运行"CMAKE_INSTALL_PREFIX=./install cmake --install build"(纠正:这里不应该跟install,而是build,从构建目录安装)。

"cmake --build build --target install"相当于是"cmake --build build"和"cmake --install build"合二为一;后者只是把构建好的东西安装在指定目录下,无法执行build操作。这与"make install"的情况确实不同,"make install"在cmake下严格等价于"cmake --build . --target install",同理"make clean"就是"cmake --build . --target clean"。
作者
Author:
Uus/pMeC6H4-/キ    时间: 2026-3-31 11:41
UW_0728. 发表于 2026-3-31 11:07
对于同一个构建流程,--target install安装到的地方就是CMAKE_INSTALL_PREFIX设置的地方,两者毫无区别, ...

明白了,这样现行开发版建议的 cmake 指令确实是比较省事的。(发帖发重了哦)之前 @乐平 提的https://github.com/cp2k/cp2k/issues/4705应该已经解决、可以关闭了。

还有一个小问题,如果已经编译安装了一次CP2K的二进制可执行文件,然后修改了./src里的fortran源代码,有没有比“用整套源代码文件在不冲突的目录下从头跑完整的build和install流程”更短的编译安装方式来做测试?
作者
Author:
UW_0728.    时间: 2026-3-31 12:16
Uus/pMeC6H4-/キ 发表于 2026-3-31 11:41
明白了,这样现行开发版建议的 cmake 指令确实是比较省事的。(发帖发重了哦)之前 @乐平 提的https://gi ...

直接进入build目录,加载好该有的环境,运行make install即可。构建系统会自动检查哪些代码发生了变化,然后只重新编译那些代码与可能受相关改动影响的另外几个代码。
作者
Author:
UW_0728.    时间: 2026-4-18 21:20
Uus/pMeC6H4-/キ 发表于 2026-3-11 12:31
我想问个小问题。上周PR #4865在更新toolchain里的libint到2.13.1版的同时也新增了系统包管理器安装boost和 ...

https://github.com/cp2k/cp2k/pull/5072 把这两个需要包管理器安装的硬依赖去掉了,eigen3不再需要,boost用libint源码包自带的




欢迎光临 计算化学公社 (http://bbs.keinsci.com/) Powered by Discuz! X3.3