igraph C 语言 在 Windows 上的编译完全版
1. MinGW64
NOTES: When using MSYS2, start the “MSYS2 MinGW 64-bit” terminal, and not the “MSYS2 MSYS” one.
参考:
https://igraph.org/c/doc/igraph-Installation.html#igraph-Installation-msys2
使用下面的命令更新软件包:
$ pacman --disable-download-timeout -Syuu $PACKAGES
$PACKAGES 取下面的包名.
必须要求:
mingw-w64-x86_64-toolchain
必须安装 mingw64 的 cmake (不能使用windows上的【如果有】)
mingw-w64-x86_64-cmake
把功能配置拉满,强烈建议:
mingw-w64-x86_64-gmp mingw-w64-x86_64-libxml2
追求极致性能,强烈建议:
mingw-w64-x86_64-openblas mingw-w64-x86_64-arpack mingw-w64-x86_64-glpk
仅开发版使用:
diffutils git bison flex
以上安装完毕,检查:
$ cmake --version
cmake version 3.31.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ which cmake
/mingw64/bin/cmake
编译 igraph 动态库 (on MinGW64)
下载后解压:
https://github.com/igraph/igraph/releases/download/0.10.15/igraph-0.10.15.tar.gz
$ cd igraph-0.10.15/
$ mkdir build
$ cd build
# cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
实际使用下面的设置(-G “MSYS Makefiles” 指示生成 Makefile):
$ cmake .. -G "MSYS Makefiles" \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DCMAKE_BUILD_TYPE=Release \
-DIGRAPH_USE_INTERNAL_BLAS=OFF \
-DIGRAPH_USE_INTERNAL_LAPACK=OFF \
-DIGRAPH_USE_INTERNAL_ARPACK=OFF \
-DIGRAPH_USE_INTERNAL_GLPK=OFF \
-DIGRAPH_USE_INTERNAL_GMP=OFF \
-DIGRAPH_USE_INTERNAL_PLFIT=ON \
-DBLA_VENDOR=OpenBLAS \
-DIGRAPH_GRAPHML_SUPPORT=ON \
-DIGRAPH_ENABLE_LTO=ON \
-DBUILD_SHARED_LIBS=ON
-- Version number: 0.10.15
-- Found BLAS: C:/DEVPACK/msys64/mingw64/lib/libopenblas.dll.a
-- Found GLPK: C:/DEVPACK/msys64/mingw64/lib/libglpk.dll.a (found suitable version "5.0", minimum required is "4.57")
-- Looking for cheev_
-- Looking for cheev_ - found
-- Found LAPACK: C:/DEVPACK/msys64/mingw64/lib/libopenblas.dll.a;C:/DEVPACK/msys64/mingw64/lib/libopenblas.dll.a
-- Found ARPACK: C:/DEVPACK/msys64/mingw64/lib/libarpack.dll.a
-- Found GMP: C:/DEVPACK/msys64/mingw64/lib/libgmp.dll.a
-- Found LibXml2: C:/DEVPACK/msys64/mingw64/lib/libxml2.dll.a (found version "2.12.9")
--
-- -----[ Build configuration ]----
-- Version: 0.10.15
-- CMake build type: Release
-- Library type: shared
-- igraph_integer_t size: 64 bits
--
-- ----------[ Features ]----------
-- GLPK for optimization: yes
-- Reading GraphML files: yes
-- Thread-local storage: yes
-- Link-time optimization: yes
--
-- --------[ Dependencies ]--------
-- ARPACK: yes
-- BISON: yes
-- BLAS: yes
-- FLEX: yes
-- GLPK: yes
-- GMP: yes
-- LAPACK: yes
-- LibXml2: yes
-- OpenMP: yes
-- PLFIT: vendored
--
-- -----------[ Testing ]----------
-- Diff tool: diff
-- Sanitizers: none
-- Code coverage: no
-- Verify 'finally' stack: no
--
-- --------[ Documentation ]-------
-- HTML: no
-- PDF: no
-- INFO: no
--
-- igraph configured successfully.
--
-- Configuring done (12.4s)
-- Generating done (16.3s)
-- Build files have been written to: C:/WORKSPACE/VULKAN_DEV/mapaware.top/deps-win32/igraph-0.10.15/build
最后开始编译正式优化完全功能版的动态库并安装到指定位置(-DCMAKE_INSTALL_PREFIX=/usr/local/igraph):
$ make
$ make install
2. Visual Studio 2022 (on msvc)
Win10 上已经安装了 VS2022。因为 VS2022 的项目没法使用 1. MINGW64 编译的库,所以要单独为 VS 编译。
依赖关系:
igraph (其中的 graphml) -> libxml2 -> libiconv -> zlib。
所以需要 libxml2,而 libxml2 又依赖 libiconv。这2个库使用 VS 编译都非常难,所以使用 MINGW64 自带的(编译好的)。在:
"C:\DEVPACK\msys64\usr" (MSYS2 命令行路径:/usr)
下载如下的源码:
- https://github.com/igraph/igraph/releases/download/0.10.15/igraph-0.10.15.tar.gz
解压后创建子目录: igraph-0.10.15\build
下载 CMake-gui on Windows
- https://github.com/Kitware/CMake/releases/download/v3.31.2/cmake-3.31.2-windows-x86_64.zip
这里不能使用 MSYS2 里面的 cmake。所以我们另外下载,解压后双击:“安装位置\CMake\bin\cmake-gui.exe”
打开一个图形界面。主要就是配置这个界面如下:
然后把 “C:\DEVPACK\msys64\usr\include” (MSYS2 命令行路径:/usr/include/) 下面的:
localcharset.h
libcharset.h
iconv.h
复制到 igraph-0.10.15\include\。最后按 1,2,3 按钮操作,VS2022 打开工程(igraph-0.10.15\build\igraph.sln)。编译即可。最后复制编译好的文件到
发布目录(在任何位置创建的目录,例如:igraph-msvc):
igraph-0.10.15\COPYING => igraph-msvc\
igraph-0.10.15\IGRAPH_VERSION => igraph-msvc\
igraph-0.10.15\include\*.h => igraph-msvc\include\igraph\ (去掉:localcharset.h, libcharset.h, iconv.h)
igraph-0.10.15\build\include\*.h => igraph-msvc\include\igraph\
igraph-0.10.15\build\src\Debug\* => igraph-msvc\lib\x64\Debug\
igraph-0.10.15\build\src\Release\* => igraph-msvc\lib\x64\Release\
这样,igraph-msvc 目录就是编译好的 igraph 动态库和头文件。可以在 VS2022 的工程里使用了。当然,MinGW64 的项目仍然需要使用 MinGW64 的编译的。