homenc / HElib

HElib is an open-source software library that implements homomorphic encryption. It supports the BGV scheme with bootstrapping and the Approximate Number CKKS scheme. HElib also includes optimizations for efficient homomorphic evaluation, focusing on effective use of ciphertext packing techniques and on the Gentry-Halevi-Smart optimizations.
https://homenc.github.io/HElib
Other
3.11k stars 759 forks source link

Unable to compile example program in C++ 11 #473

Closed lutonelli closed 2 years ago

lutonelli commented 2 years ago

I have to use HElib for my thesis, so I installed it and tried the examples from HElib/examples/tutorial, in order to start encoding some data. I installed HElib following the INSTALL.md document and ran the examples as said in examples/README.md. I'm able to build the examples, get their executables and run them.

Then I tried writing a little program and compile it, but I obtain some errors. If I just include the header of HElib the program compiles and runs correctly, as in:

#include <helib/helib.h>

using namespace std;
using namespace helib;

int main(int argc, char* argv[])
{

    cout << "hello world" << "\n";

    return 0;
}

But when I try to use some HElib classes the program does not compile with "undefined reference" errors. The code I'm trying to compile is simple and taken from the HElib examples:

#include <helib/helib.h>

using namespace std;
using namespace helib;

int main(int argc, char* argv[])
{

    Context context = ContextBuilder<CKKS>().m(16 * 1024).bits(119).precision(20).c(2).build();

    cout << "distance=" << "\n";

    return 0;
}

I'm trying compiling it with:

g++-11 encrypt_mnist.cpp -o encrypt_mnist -I/home/lulu/helib_install/helib_pack/include

and the error I get in this case is:

/usr/bin/ld: /tmp/cccLr3H1.o: in function `main':
encrypt_mnist.cpp:(.text+0x9e): undefined reference to `helib::ContextBuilder<helib::CKKS>::build() const'
/usr/bin/ld: /tmp/cccLr3H1.o: in function `NTL::ZZ::Deleter::apply(_ntl_gbigint_body*)':
encrypt_mnist.cpp:(.text._ZN3NTL2ZZ7Deleter5applyEP17_ntl_gbigint_body[_ZN3NTL2ZZ7Deleter5applyEP17_ntl_gbigint_body]+0x18): undefined reference to `_ntl_gfree(_ntl_gbigint_body*)'
collect2: error: ld returned 1 exit status

I tried also compiling it with

-I/home/lulu/helib_install/helib_pack/lib 
-L/home/lulu/helib_install/helib_pack/lib 
-L/home/lulu/helib_install/helib_pack/lib -lhelib 
-I/home/lulu/helib_install/helib_pack/lib -L/home/lulu/helib_install/helib_pack/lib -lhelib

but none of the above options seem to work. The first three for example give me a "no such file or directory" error with respect to helib.h. The latter instead produces a lot of errors like the one I posted above.

My knowledge of C++ is very low, but no one seems to be able to help me.

Thanks in advance for the help.

lutonelli commented 2 years ago

This problem found a solution in this Stack Overflow question.