fplll 重载虚函数,导致 clang make 出错的解决方案
2024-12-13
10 min read
事发
OS: macOS 14.7
brew install cmake mpfr libomp gmp fplll
接着 mkdir build && cd build && cmake ..
错误记录(macOS)
user@host ~/D/C/t/flatter> mkdir build && cd build main
user@host ~/D/C/t/f/build> cmake -DCMAKE_CXX_FLAGS="-Wno-overloaded-virtual" .. main
-- The CXX compiler identification is Clang 19.1.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/homebrew/opt/llvm/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.1")
-- Found OpenMP: TRUE (found version "5.1")
-- Found GMP: /opt/homebrew/include
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Looking for dgemm_
-- Looking for dgemm_ - found
-- Found BLAS: /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/Accelerate.framework
-- Looking for cheev_
-- Looking for cheev_ - found
-- Found LAPACK: /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/Accelerate.framework;-lm;-ldl
-- Found MPFR: /opt/homebrew/include (Required is at least version "1.0.0")
-- Found FPLLL: /opt/homebrew/include (found suitable version "5.5.0", minimum required is "5.1.0")
-- Configuring done (2.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/user/Documents/Code/tools/flatter/build
user@host ~/D/C/t/f/build> make main?
[ 1%] Building CXX object src/CMakeFiles/flatter.dir/math/matrix_tools.cpp.o
[ 2%] Building CXX object src/CMakeFiles/flatter.dir/math/mpfr_blas.cpp.o
[ 3%] Building CXX object src/CMakeFiles/flatter.dir/math/mpfr_lapack.cpp.o
[ 5%] Building CXX object src/CMakeFiles/flatter.dir/problems/problem.cpp.o
[ 6%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/fused_qr_size_reduction.cpp.o
[ 7%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/base.cpp.o
[ 9%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/columnwise.cpp.o
[ 10%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/columnwise_double.cpp.o
[ 11%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/iterated.cpp.o
[ 12%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/lazy_refine.cpp.o
[ 14%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/params.cpp.o
[ 15%] Building CXX object src/CMakeFiles/flatter.dir/problems/fused_qr_sizered/seysen_refine.cpp.o
[ 16%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/matrix_multiplication.cpp.o
[ 18%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/base.cpp.o
[ 19%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/aliased.cpp.o
[ 20%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/elementary_mpfr.cpp.o
[ 22%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/elementary_mpz.cpp.o
[ 23%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/elementary_native.cpp.o
[ 24%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/elementary_RRZ.cpp.o
[ 25%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/elementary_RRl.cpp.o
[ 27%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/elementary_ZZl.cpp.o
[ 28%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/strassen.cpp.o
[ 29%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/threaded.cpp.o
[ 31%] Building CXX object src/CMakeFiles/flatter.dir/problems/matrix_multiplication/tri_matmul.cpp.o
[ 32%] Building CXX object src/CMakeFiles/flatter.dir/problems/qr_factorization/base.cpp.o
[ 33%] Building CXX object src/CMakeFiles/flatter.dir/problems/qr_factorization/blocked.cpp.o
[ 35%] Building CXX object src/CMakeFiles/flatter.dir/problems/qr_factorization/householder_mpfr.cpp.o
[ 36%] Building CXX object src/CMakeFiles/flatter.dir/problems/qr_factorization/eigen_impl.cpp.o
[ 37%] Building CXX object src/CMakeFiles/flatter.dir/problems/qr_factorization/qr_factorization.cpp.o
[ 38%] Building CXX object src/CMakeFiles/flatter.dir/problems/qr_factorization/threaded.cpp.o
[ 40%] Building CXX object src/CMakeFiles/flatter.dir/problems/lattice_reduction/base.cpp.o
[ 41%] Building CXX object src/CMakeFiles/flatter.dir/problems/lattice_reduction/fplll_impl.cpp.o
In file included from /Users/user/Documents/Code/tools/flatter/src/problems/lattice_reduction/fplll_impl.cpp:1:
In file included from /Users/user/Documents/Code/tools/flatter/src/problems/lattice_reduction/fplll_impl.h:3:
In file included from /opt/homebrew/include/fplll/fplll.h:25:
In file included from /opt/homebrew/include/fplll/bkz.h:21:
In file included from /opt/homebrew/include/fplll/bkz_param.h:24:
In file included from /opt/homebrew/include/fplll/pruner/pruner.h:21:
In file included from /opt/homebrew/include/fplll/pruner/../lll.h:21:
/opt/homebrew/include/fplll/pruner/../gso.h:221:16: error: 'fplll::MatGSO<fplll::Z_NR<>, fplll::FP_NR<>>::babai' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
221 | void virtual babai(vector<ZT> &v, int start = 0, int dimension = -1, bool gso = false);
| ^
/Users/user/Documents/Code/tools/flatter/src/problems/lattice_reduction/fplll_impl.cpp:144:65: note: in instantiation of template class 'fplll::MatGSO<fplll::Z_NR<>, fplll::FP_NR<>>' requested here
144 | fplll::MatGSO<fplll::Z_NR<mpz_t>, fplll::FP_NR<mpfr_t>> m_gso(this->A, fplll_U, u_inv, gso_flags);
| ^
/opt/homebrew/include/fplll/pruner/../gso_interface.h:469:16: note: hidden overloaded virtual function 'fplll::MatGSOInterface<fplll::Z_NR<>, fplll::FP_NR<>>::babai' declared here: different number of parameters (3 vs 4)
469 | void virtual babai(vector<ZT> &v, int start = 0, int dimension = -1);
| ^
/opt/homebrew/include/fplll/pruner/../gso_interface.h:480:16: note: hidden overloaded virtual function 'fplll::MatGSOInterface<fplll::Z_NR<>, fplll::FP_NR<>>::babai' declared here: type mismatch at 2nd parameter ('const vector<FP_NR<__mpfr_struct[1]>> &' vs 'int')
480 | void virtual babai(vector<ZT> &w, const vector<FT> &v, int start = 0, int dimension = 1);
| ^
In file included from /Users/user/Documents/Code/tools/flatter/src/problems/lattice_reduction/fplll_impl.cpp:1:
In file included from /Users/user/Documents/Code/tools/flatter/src/problems/lattice_reduction/fplll_impl.h:3:
In file included from /opt/homebrew/include/fplll/fplll.h:25:
In file included from /opt/homebrew/include/fplll/bkz.h:21:
In file included from /opt/homebrew/include/fplll/bkz_param.h:24:
In file included from /opt/homebrew/include/fplll/pruner/pruner.h:21:
In file included from /opt/homebrew/include/fplll/pruner/../lll.h:21:
/opt/homebrew/include/fplll/pruner/../gso.h:233:16: error: 'fplll::MatGSO<fplll::Z_NR<>, fplll::FP_NR<>>::babai' hides overloaded virtual functions [-Werror,-Woverloaded-virtual]
233 | void virtual babai(vector<ZT> &w, const vector<FT> &v, int start = 0, int dimension = -1,
| ^
/opt/homebrew/include/fplll/pruner/../gso_interface.h:469:16: note: hidden overloaded virtual function 'fplll::MatGSOInterface<fplll::Z_NR<>, fplll::FP_NR<>>::babai' declared here: different number of parameters (3 vs 5)
469 | void virtual babai(vector<ZT> &v, int start = 0, int dimension = -1);
| ^
/opt/homebrew/include/fplll/pruner/../gso_interface.h:480:16: note: hidden overloaded virtual function 'fplll::MatGSOInterface<fplll::Z_NR<>, fplll::FP_NR<>>::babai' declared here: different number of parameters (4 vs 5)
480 | 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/build.make:513: src/CMakeFiles/flatter.dir/problems/lattice_reduction/fplll_impl.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:373: src/CMakeFiles/flatter.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
user@host ~/D/C/t/f/build> 2 main?
解决方案
询问 CPP 大师: M1saka
于是为 CMake 传递参数,让 clang 不要把重载虚函数的警告作为错误, 顺便传递一些库,避免找不到 lib
macOS 可以使用像我一样的脚本, 提前用 brew 安装好需要的库
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-Wno-error -Wno-overloaded-virtual -Wno-error=overloaded-virtual -I/opt/homebrew/opt/mpfr/include -I/opt/homebrew/opt/libomp/include -I/opt/homebrew/opt/gmp/include" \
-DCMAKE_C_FLAGS="-Wno-error -Wno-overloaded-virtual -Wno-error=overloaded-virtual -I/opt/homebrew/opt/mpfr/include -I/opt/homebrew/opt/libomp/include -I/opt/homebrew/opt/gmp/include" \
-DCMAKE_CXX_FLAGS_RELEASE="-Wno-error -Wno-overloaded-virtual -Wno-error=overloaded-virtual -I/opt/homebrew/opt/mpfr/include -I/opt/homebrew/opt/libomp/include -I/opt/homebrew/opt/gmp/include" \
-DCMAKE_C_FLAGS_RELEASE="-Wno-error -Wno-overloaded-virtual -Wno-error=overloaded-virtual -I/opt/homebrew/opt/mpfr/include -I/opt/homebrew/opt/libomp/include -I/opt/homebrew/opt/gmp/include" ..
产物放在了 正规子群 的 Github 组织仓库 - macOS Release
错误记录(Linux)
OS: Ubuntu server(aliyun)
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find BLAS (missing: BLAS_LIBRARIES)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindBLAS.cmake:810 (find_package_handle_standard_args)
/usr/share/cmake-3.16/Modules/FindLAPACK.cmake:197 (find_package)
src/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/admin/flatter-main/build/CMakeFiles/CMakeOutput.log".
See also "/home/admin/flatter-main/build/CMakeFiles/CMakeError.log".
除了 官方的安装说明 所安装的外, 还需安装一些包, 这里一并给出
sudo apt-get install -y build-essential cmake gcc g++ git libblas-dev liblapack-dev libgmp-dev libmpfr-dev libomp-dev
接着 cmake ..
SOLVED