c++linkerlatticereduction

correctly using fplll as c++ library


I'm trying to use the bkz_reduction function of the fplll library in my c++ programm, however, I always get an "undefined reference to `fplll::bkz_reduction(fplll::ZZ_mat<__mpz_struct [1]>&, int, int, fplll::FloatType, int)'" error.

Setup: I downloaded and installed fplll as described in the git (https://github.com/fplll/fplll/tree/master) under the 'install from source' on my wsl2 Ubuntu 22.04.3 (host: Windows 11). It is now under /home/my_username/fplll. When running the test_bkz that is included in the git, there are no problems at all.

What I want: I have a file test_stuff.cpp that includes a call of the bkz_reduction function:

...
#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;
}

Additionally I have a Makefile with

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

Calling 'make test_stuff' yields the mentioned "undefined reference to `fplll::bkz_reduction(fplll::ZZ_mat<__mpz_struct [1]>&, int, int, fplll::FloatType, int)'" error.

I have double-checked the correct input parameters of the function and the required types match. My VSCode has no troubles finding the bkz_reduction function and has also no objections regarding the function call.

After reading different internet contents, I assume that I'm not linking the fplll library correctly to my test_stuff program, however, my knowledge of linking is very limited. I tried to understand the Makefile of the test_bkz in the official fplll-git repository, but it's unfortunately too complex for me as a beginner.

I would appreciate any help or suggestions what to try. Seeing a correctly functioning example would also be great, anything I found used the python version fpylll to get access to the fplll functions.


Solution

  • You don't seem to tell the linker to link with fplll at all. Luckily this library ships a pkg-config file so you can ask pkg-config for the flags:

    test_stuff: tests/test_stuff.cpp
        $(CXX) $(CXXFLAGS) tests/test_stuff.cpp -o tests/test_stuff -lmpfr -lgmp `pkg-config --libs fplll`