flatter是一个开源项目,能大大提高LLL的速度,项目提供的安装文档适用于Ubuntu,但是在macos上安装,总会遇到各种各样的问题,这里记录下所踩坑,帮助大家快速在macos上安装flatter。
各种报错的解决全部掺杂在小步骤里面了,如果按照步骤来,仍有报错,欢迎在评论区讨论。
正确步骤1:clone flatter项目。
git clone https://github.com/keeganryan/flatter.git
正确步骤2:首先安装如下依赖,这里和项目文档有些出入,这些都是踩坑的教训。
brew install gmp mpfr eigen llvm libomp
正确步骤3:安装fplll的5.4.2版本,参考博客:HomeBrew安装历史版本依赖库(formula)-4.0以后版本通用(以brew安装fplll5.4.2为例)
然后fplll不能直接安装,直接安装的话,默认安装的是新版,新版有不兼容问题,在make的时候会报如下错误:
/opt/homebrew/include/fplll/gso.h:233:16: error: 'fplll::MatGSO<fplll::Z_NR<>, fplll::FP_NR<>>::babai' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
void virtual babai(vector<ZT> &w, const vector<FT> &v, int start = 0, int dimension = -1,
^
/opt/homebrew/include/fplll/gso_interface.h:466:16: note: hidden overloaded virtual function 'fplll::MatGSOInterface<fplll::Z_NR<>, fplll::FP_NR<>>::babai' declared here: different number of parameters (3 vs 5)
void virtual babai(vector<ZT> &v, int start = 0, int dimension = -1);
^
/opt/homebrew/include/fplll/gso_interface.h:477:16: note: hidden overloaded virtual function 'fplll::MatGSOInterface<fplll::Z_NR<>, fplll::FP_NR<>>::babai' declared here: different number of parameters (4 vs 5)
void virtual babai(vector<ZT> &w, const vector<FT> &v, int start = 0, int dimension = 1);
^
2 errors generated.
make[2]: *** [src/CMakeFiles/flatter.dir/problems/lattice_reduction/fplll_impl.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/flatter.dir/all] Error 2
make: *** [all] Error 2
这个错误的解决办法,就是使用低版本的fplll库,这里使用5.4.2,保证不会有问题。
安装完依赖后,不能直接cmake,这样的话,会遇到如下的报错:
atfwus@***MacBook-Pro build % cmake ..
CMake Error at /opt/homebrew/Cellar/cmake/3.27.7/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
Call Stack (most recent call first):
/opt/homebrew/Cellar/cmake/3.27.7/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/opt/homebrew/Cellar/cmake/3.27.7/share/cmake/Modules/FindOpenMP.cmake:577 (find_package_handle_standard_args)
src/CMakeLists.txt:8 (find_package)
正确步骤4:我们需要在CMakeLists.txt文件中显式指定OpenMP路径:
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/opt/homebrew/opt/libomp/include")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY "/opt/homebrew/opt/libomp/lib/libomp.a")
set(OpenMP_CXX_VERSION 3.1)
特别注意这几行添加的位置,是位于flatter-main/CMakeLists.txt中的这个位置,添加错位置了也会出问题:
正确步骤5:然后还需要指定mpfr和gmp的依赖位置:
include_directories(/opt/homebrew/opt/mpfr/include)
include_directories(/opt/homebrew/opt/gmp/include)
link_directories(/opt/homebrew/opt/mpfr/lib)
link_directories(/opt/homebrew/opt/gmp/lib)
如果这里没指定,那么在make的时候会遇到如下的错误:
[ 98%] Building CXX object apps/CMakeFiles/flatter_bin.dir/flatter.cpp.o
In file included from /Users/atfwus/open_proj/flatter-main/apps/flatter.cpp:2:
In file included from /Users/atfwus/open_proj/flatter-main/./include/flatter/data/matrix.h:1:
/Users/atfwus/open_proj/flatter-main/./include/flatter/data/matrix/matrix.h:3:10: fatal error: 'mpfr.h' file not found
#include <mpfr.h>
^~~~~~~~
1 error generated.
make[2]: *** [apps/CMakeFiles/flatter_bin.dir/flatter.cpp.o] Error 1
make[1]: *** [apps/CMakeFiles/flatter_bin.dir/all] Error 2
正确步骤6:编译
mkdir build && cd ./build
cmake ..
make
sudo make install
sudo update_dyld_shared_cache
如果上面的步骤都做到了的话,这几步都不会出现问题,如果出现了问题,去上面步骤里面找报错信息。
正确步骤7:设置环境变量DYLD_LIBRARY_PATH
进入lib目录,查看当前路径,例如:/Users/atfwus/open_proj/flatter-main/build/lib
编辑~/.zprofile文件(依据你使用的shell不同而不同,有的是.bashrc),将其添加到末尾:
# flatter DYLD
export DYLD_LIBRARY_PATH=/Users/atfwus/open_proj/flatter-main/build/lib:$DYLD_LIBRARY_PATH
source .zprofile
这样就成功安装flatter了,可以检验是否安装成功:
atfwus@xxxMacBook-Pro build % latticegen q 4 2 10 b | flatter
[[4 -1 1 0]
[2 10 8 2]
[1 4 -5 -13]
[4 4 -12 12]
]
如果第7步出现了问题,那么运行上述命令的时候,会有如下报错:
atfwus@xxxMacBook-Pro ~ % flatter
dyld[91789]: Library not loaded: @rpath/libflatter.dylib
Referenced from: <945BAD71-AAEC-35CD-AA40-C43693D76181> /usr/local/bin/flatter
Reason: no LC_RPATH's found
zsh: abort flatter
ATFWUS 2024-01-18