Monday, August 3, 2015

Homomorphic-Simon implementation: Flint library compile error

g++ -I/usr/local/include -I/opt/local/include -O3 -fopenmp -Wall -pedantic -DYASHE -o Simon main.o Simon.o timing.o YASHE/BitVector.o YASHE/Ciphertext.o YASHE/Entropy.o YASHE/Sampler.o YASHE/YASHEKey.o -L/opt/local/lib -lgmp -lgmpxx -lcrypto -lm -lmpfr -lflint
main.o: In function `YASHEParams::~YASHEParams()':
main.cpp:(.text._ZN11YASHEParamsD2Ev[_ZN11YASHEParamsD5Ev]+0x39): undefined reference to `_fmpz_clear_mpz'
main.cpp:(.text._ZN11YASHEParamsD2Ev[_ZN11YASHEParamsD5Ev]+0x51): undefined reference to `_fmpz_clear_mpz'
main.cpp:(.text._ZN11YASHEParamsD2Ev[_ZN11YASHEParamsD5Ev]+0x74): undefined reference to `_fmpz_clear_mpz'
main.o: In function `std::vector<Ciphertext, std::allocator<Ciphertext> >::~vector()':
main.cpp:(.text._ZNSt6vectorI10CiphertextSaIS0_EED2Ev[_ZNSt6vectorI10CiphertextSaIS0_EED5Ev]+0x1d): undefined reference to `fmpz_mod_poly_clear'
main.o: In function `std::vector<std::vector<Ciphertext, std::allocator<Ciphertext> >, std::allocator<std::vector<Ciphertext, std::allocator<Ciphertext> > > >::~vector()':
main.cpp:(.text._ZNSt6vectorIS_I10CiphertextSaIS0_EESaIS2_EED2Ev[_ZNSt6vectorIS_I10CiphertextSaIS0_EESaIS2_EED5Ev]+0x35): undefined reference to `fmpz_mod_poly_clear'
main.o: In function `void std::__uninitialized_fill_n<false>::__uninit_fill_n<std::vector<Ciphertext, std::allocator<Ciphertext> >*, unsigned long, std::vector<Ciphertext, std::allocator<Ciphertext> > >(std::vector<Ciphertext, std::allocator<Ciphertext> >*, unsigned long, std::vector<Ciphertext, std::allocator<Ciphertext> > const&)':
main.cpp:(.text._ZNSt22__uninitialized_fill_nILb0EE15__uninit_fill_nIPSt6vectorI10CiphertextSaIS3_EEmS5_EEvT_T0_RKT1_[_ZNSt22__uninitialized_fill_nILb0EE15__uninit_fill_nIPSt6vectorI10CiphertextSaIS3_EEmS5_EEvT_T0_RKT1_]+0x113): undefined reference to `fmpz_mod_poly_clear'
main.o: In function `main':
main.cpp:(.text.startup+0x6f): undefined reference to `fmpz_set_str'
main.cpp:(.text.startup+0x7c): undefined reference to `fmpz_cmp'
main.cpp:(.text.startup+0x531): undefined reference to `_fmpz_clear_mpz'

main.cpp:(.text.startup+0x5b1): undefined reference to `_fmpz_clear_mpz'
...
...
...

YASHE/YASHEKey.o:YASHEKey.cpp:(.text._ZNSt6vectorIN5flint26fmpz_mod_polyxx_expressionINS0_10operations9immediateENS0_6detail18fmpz_mod_poly_dataEEESaIS6_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS6_S8_EEmRKS6_[_ZNSt6vectorIN5flint26fmpz_mod_polyxx_expressionINS0_10operations9immediateENS0_6detail18fmpz_mod_poly_dataEEESaIS6_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS6_S8_EEmRKS6_]+0x4d4): more undefined references to `fmpz_mod_poly_clear' follow
collect2: error: ld returned 1 exit status


This is caused by the installation of the old flint library. Typically done by apt-get install. 
So get remove the error, you need to run
$> sudo apt-get remove libflint-dev

then soft symlink the flint.h to the /usr/local/include/ by this command
$> sudo ln -s /usr/local/include/flint/flint.h /usr/local/include/flint.h


LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH

then it should work.

RISC-v emulator

Changes are based on https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html For Ubuntu/Debian, in addition to sud...