正确使用fplll作为C++库

问题描述 投票:0回答:1

我试图在我的c++程序中使用fplll库的bkz_reduction函数,但是,我总是得到一个“对‘fplll::bkz_reduction(fplll::ZZ_mat<__mpz_struct [1]>&, int, int, fplll::FloatType)的未定义引用” , int)'" 错误。

安装:我按照 git (https://github.com/fplll/fplll/tree/master) 中所述在我的 wsl2 Ubuntu 22.04.3(主机:Windows)上的“从源代码安装”下下载并安装了 fplll 11)。现在它位于 /home/my_username/fplll 下。 运行git中包含的test_bkz时,完全没有问题。

我想要什么:我有一个文件 test_stuff.cpp,其中包含 bkz_reduction 函数的调用:

...
#include <cstring>
#include <cstdlib>
#include <fplll.h>


using namespace std;
using namespace fplll;


int main()
{
    ...
    ZZ_mat<mpz_t> fplll_mat;
    fplll_mat = //gets set to some other value;

    int status = 0;
    status = bkz_reduction(fplll_mat, 10, BKZ_DEFAULT, FT_DEFAULT, 0);

    return 0;
}

另外我还有一个 Makefile

CFLAGS = -Wall -Wextra -march=native -mtune=native -O3 -fomit-frame-pointer
CXX = g++
CXXFLAGS = $(CFLAGS) -std=c++0x

test_stuff: tests/test_stuff.cpp
    $(CXX) $(CXXFLAGS) tests/test_stuff.cpp -o tests/test_stuff -lmpfr -lgmp

调用“make test_stuff”会产生上述“对‘fplll::bkz_reduction(fplll::ZZ_mat<__mpz_struct [1]>&, int, int, fplll::FloatType, int)’的未定义引用”错误。

我已经仔细检查了函数的正确输入参数和所需的类型是否匹配。我的 VSCode 可以轻松找到 bkz_reduction 函数,并且对函数调用也没有异议。

在阅读了不同的互联网内容后,我认为我没有将 fplll 库正确链接到我的 test_stuff 程序,但是,我的链接知识非常有限。我试图理解官方 fplll-git 存储库中 test_bkz 的 Makefile,但不幸的是,它对我这个初学者来说太复杂了。

如果有任何帮助或建议,我将不胜感激。看到一个正常运行的示例也很棒,我发现的任何东西都使用 python 版本 fpylll 来访问 fplll 函数。

c++ linker lattice reduction
1个回答
0
投票

您似乎根本没有告诉链接器与 fplll 链接。 幸运的是,这个库提供了一个 pkg-config 文件,因此您可以向

pkg-config
询问标志:

test_stuff: tests/test_stuff.cpp
    $(CXX) $(CXXFLAGS) tests/test_stuff.cpp -o tests/test_stuff -lmpfr -lgmp `pkg-config --libs fplll`
© www.soinside.com 2019 - 2024. All rights reserved.