herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
450 stars 152 forks source link

undefined reference problem when link with mcl #148

Closed xianglingzhang closed 1 year ago

xianglingzhang commented 1 year ago

Hi, I used "libmcl.a" as a static library to build my project in Ubuntu20.04 but I met this problem:

/usr/bin/ld: CMakeFiles/test_dh_psi.dir/test/test_dh_psi.cpp.o: in function `mcl::FpT<TagZn, 512ul>::init(bool*, int, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&, mcl::fp::Mode)':
/usr/local/include/mcl/fp.hpp:171: undefined reference to `mcl::fp::Op::init(__gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&, unsigned long, int, mcl::fp::Mode, unsigned long)'
/usr/bin/ld: CMakeFiles/test_dh_psi.dir/test/test_dh_psi.cpp.o: in function `mcl::FpT<mcl::FpTag, 512ul>::init(bool*, int, __gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&, mcl::fp::Mode)':
/usr/local/include/mcl/fp.hpp:171: undefined reference to `mcl::fp::Op::init(__gmp_expr<__mpz_struct [1], __mpz_struct [1]> const&, unsigned long, int, mcl::fp::Mode, unsigned long)'
xianglingzhang commented 1 year ago
typedef mcl::FpT<> Fp;
struct tagZn;
typedef mcl::FpT<tagZn> Zn;
typedef mcl::EcT<Fp> Ec;

Ec g;
mcl::initCurve<Ec, Zn>(MCL_SECP256K1, &g);

Is this the right way to initiate the curve in mcl ? Seems like it causes the problem.

herumi commented 1 year ago

The error occurs when libmcl.a is built with MCL_USE_GMP=off (with -DMCL_USE_VINT) and and cpp is built without -DMCL_USE_VINT. Could you try to compile your code with -DMCL_USE_VINT and link it with the same libmcl.a?

xianglingzhang commented 1 year ago

It helps, thanks a lot !!!