文章目录
主要编译命令:
mkdir -p build && cd build cmake .. cmake --build . sudo cmake --install .
一、arm64架构不匹配
错误信息:
-macosx_version_min has been renamed to -macos_version_min ld: warning: ignoring duplicate libraries: ‘-lgcc’, ‘-lgcc_s.1.1’ ld: warning: ignoring file ‘/Desktop/SuiteSparse-dev/build/AMD/CMakeFiles/AMD.dir/Source/amd_1.c.o’: found architecture ‘arm64’, required architecture ‘x86_64’
解决:
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 ..
二、CholMOD编译问题
Desktop/SuiteSparse-dev/SuiteSparse_config/SuiteSparse_config.h:684:6: error: expected ‘)’ void SUITESPARSE_BLAS_DGEMV( Desktop/SuiteSparse-dev/SuiteSparse_config/SuiteSparse_config.h:593:37: note: expanded from macro ‘SUITESPARSE_BLAS_DGEMV’ #define SUITESPARSE_BLAS_DGEMV SUITESPARSE_BLAS ( dgemv , DGEMV )
CholMOD编译有问题,解决方案参考:Issues · DrTimothyAldenDavis/SuiteSparse (github.com)
具体操作,在CmakeLists.txt
中添加:
# 添加 BLAS_UNDERSCORE 定义到 C 编译器标志 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBLAS_UNDERSCORE") # 添加 BLAS_UNDERSCORE 定义到 C++ 编译器标志 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBLAS_UNDERSCORE")
三、gmp和mpfr架构不匹配
ld: warning: ignoring file ‘/opt/homebrew/Cellar/mpfr/4.2.1/lib/libmpfr.6.dylib’: found architecture ‘arm64’, required architecture ‘x86_64’
ld: warning: ignoring file ‘/opt/homebrew/Cellar/gmp/6.3.0/lib/libgmp.10.dylib’: found architecture ‘arm64’, required architecture ‘x86_64’
需要重新下载x86_64架构的包,那么需要重新下载inter架构的intel,下载命令如下:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
需要先确保新的 Homebrew 路径在你的 PATH
中。编辑 ~/.zshrc
并添加:
export PATH="/usr/local/bin:$PATH"
这个路径保证brew首先用/usr/local下的针对intel的brew包,然后再用下面的命令下载x86的包:
arch -x86_64 brew install mpfr gmp
Note:
完成上面步骤后,需要删掉build重新构建SuiteSparse
记得添加路径:
export CPPFLAGS="-I/usr/local/opt/gmp/include $CPPFLAGS" export LDFLAGS="-L/usr/local/opt/gmp/lib $LDFLAGS"