本文記錄在Windows下編譯SLEPc的流程。
零、環境
操作系統 | Windows 11 |
VS Code | 1.92.1 |
MSYS2 | msys2-x86_64-20250830 |
一、安裝依賴
1.1、依賴
首先,下載并安裝MSYS2,
打開MSYS2 MINGW64控制臺,運行以下命令安裝依賴包,
pacman -S git python base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-msmpi
1.2?PETSc
?參見<Windows下編譯安裝PETSc>
二、編譯安裝
2.1 下載源碼
下載并解壓slepc-3.22.1.zip?
git clone https://github.com/slepc/slepc.git
cd ./slepc/
git checkout v3.22.1
2.2 構建
/usr/bin/python ./configure --prefix=/mingw64/arch-mswin-c-debug
2.3 編譯與安裝
make SLEPC_DIR=/mingw64/src/slepc-3.22.1 PETSC_DIR=/mingw64/src/petsc-v3.22.1 PETSC_ARCH=arch-mswin-c-debug
make SLEPC_DIR=/mingw64/src/slepc-3.22.1 PETSC_DIR=/mingw64/src/petsc-v3.22.1 install
三、使用SLEPc
# FindSLEPc
# ---------
#
# Locates the SLEPc library using pkg-config module SLEPc
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following IMPORTED target:
#
# SLEPc::SLEPc - the SLEPc library
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# SLEPc_FOUND - if false, do not try to link to SLEPc
# SLEPc_LIBRARIES - a list of the full paths to all libraries
# SLEPc_INCLUDE_DIRS - a list of all include directories
# SLEPc_VERSION - the full version of SLEPc MAJOR.MINOR.PATCH
# SLEPc_VERSION_MAJOR - the MAJOR part of SLEPc_VERSION
# SLEPc_VERSION_MINOR - the MINOR part of SLEPc_VERSION
# SLEPc_VERSION_PATCH - the PATCH part of SLEPc_VERSION
#
# Setting these changes the behavior of the search
# SLEPc_DIR - directory in which SLEPc resides
# SLEPc_ARCH - build architecture
#
# Author: nene
#
# References:
# - slepc/share/slepc/CMakeLists.txt
#cmake_policy(VERSION 3.10)set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)# set root of location to find SLEPc's pkg-config
set(PETSC $ENV{PETSC_DIR}/$ENV{PETSC_ARCH})
set(SLEPC $ENV{SLEPC_DIR}/$ENV{PETSC_ARCH})
set(ENV{PKG_CONFIG_PATH} ${PETSC}/lib/pkgconfig:${SLEPC}/lib/pkgconfig)# Remove the lines below if you do not wish to have SLEPc determine the compilers
execute_process ( COMMAND pkg-config SLEPc --variable=ccompiler COMMAND tr -d '\n' OUTPUT_VARIABLE C_COMPILER)
SET(CMAKE_C_COMPILER ${C_COMPILER})
execute_process ( COMMAND pkg-config SLEPc --variable=cxxcompiler COMMAND tr -d '\n' OUTPUT_VARIABLE CXX_COMPILER)
if (CXX_COMPILER)SET(CMAKE_CXX_COMPILER ${CXX_COMPILER})
endif (CXX_COMPILER)
execute_process ( COMMAND pkg-config SLEPc --variable=fcompiler COMMAND tr -d '\n' OUTPUT_VARIABLE FORTRAN_COMPILER)
if (FORTRAN_COMPILER)SET(CMAKE_Fortran_COMPILER ${FORTRAN_COMPILER})enable_language(Fortran)
endif (FORTRAN_COMPILER)find_package(PkgConfig REQUIRED)if(PKG_CONFIG_FOUND)pkg_search_module(SLEPc REQUIRED IMPORTED_TARGET SLEPc)# Extract version parts from the version informationif(SLEPc_VERSION)set(_SLEPc_versions "")string(REGEX MATCHALL "[0-9]+" _SLEPc_versions ${SLEPc_VERSION})list(GET _SLEPc_versions 0 _SLEPc_version_major)list(GET _SLEPc_versions 1 _SLEPc_version_minor)list(GET _SLEPc_versions 2 _SLEPc_version_patch)set(SLEPc_VERSION ${SLEPc_VERSION} CACHE STRING "Full version of SLEPc")set(SLEPc_VERSION_MAJOR ${_SLEPc_version_major} CACHE INTERNAL "Major version of SLEPc")set(SLEPc_VERSION_MINOR ${_SLEPc_version_minor} CACHE INTERNAL "Minor version of SLEPc")set(SLEPc_VERSION_PATCH ${_SLEPc_version_patch} CACHE INTERNAL "Patch version of SLEPc")unset(_SLEPc_versions)unset(_SLEPc_version_major)unset(_SLEPc_version_minor)unset(_SLEPc_version_patch)endif()
endif()include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (SLEPcREQUIRED_VARS SLEPc_FOUND SLEPc_INCLUDE_DIRS SLEPc_LIBRARIESVERSION_VAR SLEPc_VERSION)if(NOT TARGET SLEPc::SLEPc)add_library(SLEPc::SLEPc ALIAS PkgConfig::SLEPc)
endif()mark_as_advanced(SLEPc_INCLUDE_DIRS SLEPc_LIBRARIES SLEPc_VERSION_MAJOR SLEPc_VERSION_MINOR SLEPc_VERSION_PATCH VERSION_VAR SLEPc_VERSION)
網絡
SLEPc
?Windows下編譯安裝PETSc