skalenetwork / libBLS

Solidity-compatible BLS signatures, threshold encryption, distributed key generation library in modern C++. Actively maintained and used by SKALE for consensus, distributed random number gen, inter-chain communication and protection of transactions. BLS threshold signatures can be verified in Solidity, and used as random beacon (common coin)
https://skale.space
GNU Affero General Public License v3.0
145 stars 45 forks source link

Linking error 'undefined reference to '__gmp_printf'' with the dependency 'libff.a' #171

Closed gaoweihe closed 2 years ago

gaoweihe commented 2 years ago

(Environment: CLion remote development; CMake 3.22.1; gcc 9.4.0)

I got linking problem while trying to invoke libBLS. And I have changed it to rather simple code:

// main.cpp

#include <iostream>
#include "inc/libBLS.h"

int main() {
    DKGBLSWrapper dkg_obj(3, 4);
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

The CMakeLists configuration I am using is

project(tomchain)
set(CMAKE_CXX_STANDARD 14)

include_directories(inc)
link_directories(lib)

add_executable(tomchain main.cpp)

target_link_libraries(tomchain
        libbls.a
        libgmp.a
        libgcov.a
        libff.a
        libssl.a
        libcrypto.a
        libpthread.a
        libdl.so
        )

It does not work with either libgmp.a or libgmp.so. And the error message is:

Consolidate compiler generated dependencies of target tomchain
[ 50%] Linking CXX executable tomchain
/tmp/tmp.vlK1F0idmX/lib/libff.a(alt_bn128_g1.cpp.o): In function `libff::alt_bn128_G1::print_coordinates() const':
alt_bn128_g1.cpp:(.text+0x81b): undefined reference to `__gmp_printf'
/tmp/tmp.vlK1F0idmX/lib/libff.a(alt_bn128_g1.cpp.o): In function `libff::alt_bn128_G1::print() const':
alt_bn128_g1.cpp:(.text+0xc1a): undefined reference to `__gmp_printf'
/tmp/tmp.vlK1F0idmX/lib/libff.a(alt_bn128_g2.cpp.o): In function `libff::alt_bn128_G2::print_coordinates() const':
alt_bn128_g2.cpp:(.text+0xa5f): undefined reference to `__gmp_printf'
/tmp/tmp.vlK1F0idmX/lib/libff.a(alt_bn128_g2.cpp.o): In function `libff::alt_bn128_G2::print() const':
alt_bn128_g2.cpp:(.text+0x13a4): undefined reference to `__gmp_printf'
collect2: error: ld returned 1 exit status
CMakeFiles/tomchain.dir/build.make:96: recipe for target 'tomchain' failed
make[2]: *** [tomchain] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/tomchain.dir/all' failed
make[1]: *** [CMakeFiles/tomchain.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

All information around this problem I can find is https://github.com/zcash/zcash/issues/1992. But it seems not so relevant to this.

Could you help me with this problem? Thanks.

┆Issue is synchronized with this Jira Task

olehnikolaiev commented 2 years ago

hello @LuminadiaQ ! you should specify libff library before libgmp in target_link_libraries command because libff references to libgmp.

gaoweihe commented 2 years ago

Thanks a lot. It works.