0

コードの静的ビルドを作成したい (このコードをサーバー上で実行したい) と、奇妙な問題が発生します。

/usr/local/lib/libntl.a(lip.o): In function `redc(void*, void*, long, unsigned long, void*)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:3515: undefined reference to `__gmpn_addmul_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:3527: undefined reference to `__gmpn_sub_n'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_rem_struct_basic::eval(long*, void*, _ntl_tmp_vec*)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:5709: undefined reference to `__gmpn_mod_1'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_reduce_struct_montgomery::eval(void**, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:3600: undefined reference to `__gmpn_addmul_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:3612: undefined reference to `__gmpn_sub_n'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_crt_struct_basic::eval(void**, long const*, _ntl_tmp_vec*)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:4709: undefined reference to `__gmpn_addmul_1'
/usr/local/lib/libntl.a(lip.o): In function `gmod_simple(void*, void*, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2067: undefined reference to `__gmpn_tdiv_qr'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_rem_struct_fast::eval(long*, void*, _ntl_tmp_vec*)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:5749: undefined reference to `__gmpn_mod_1'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_rem_struct_medium::eval(long*, void*, _ntl_tmp_vec*)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:5793: undefined reference to `__gmpn_mod_1'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_grshift(void*, long, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1420: undefined reference to `__gmpn_rshift'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_glshift(void*, long, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1355: undefined reference to `__gmpn_lshift'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gadd(void*, void*, void**)':
/usr/include/gmp.h:2194: undefined reference to `__gmpn_sub_n'
/usr/include/gmp.h:2139: undefined reference to `__gmpn_add_n'
/usr/include/gmp.h:2194: undefined reference to `__gmpn_sub_n'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsub(void*, void*, void**)':
/usr/include/gmp.h:2139: undefined reference to `__gmpn_add_n'
/usr/include/gmp.h:2194: undefined reference to `__gmpn_sub_n'
/usr/include/gmp.h:2194: undefined reference to `__gmpn_sub_n'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsubpos(void*, void*, void**)':
/usr/include/gmp.h:2194: undefined reference to `__gmpn_sub_n'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gmul(void*, void*, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1725: undefined reference to `__gmpn_mul'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1727: undefined reference to `__gmpn_mul'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsmul(void*, long, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1792: undefined reference to `__gmpn_mul_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1790: undefined reference to `__gmpn_lshift'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsdiv(void*, long, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1850: undefined reference to `__gmpn_divrem_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1848: undefined reference to `__gmpn_rshift'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsmod(void*, long)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1915: undefined reference to `__gmpn_mod_1'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gdiv(void*, void*, void**, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:1989: undefined reference to `__gmpn_tdiv_qr'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_crt_struct_fast::eval(void**, long const*, _ntl_tmp_vec*)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:4668: undefined reference to `__gmpn_addmul_1'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsqrt(void*, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2105: undefined reference to `__gmpn_sqrtrem'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gsqrts(long)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2131: undefined reference to `__gmpn_sqrtrem'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_ggcd(void*, void*, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2187: undefined reference to `__gmpn_gcd'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2185: undefined reference to `__gmpn_gcd'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gexteucl(void*, void**, void*, void**, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2536: undefined reference to `__gmpn_gcdext'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_ginv(void*, void*, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:2652: undefined reference to `__gmpn_gcdext'
/usr/local/lib/libntl.a(lip.o): In function `_ntl_gaorsmul_1(void*, long, long, void**)':
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:5963: undefined reference to `__gmpn_addmul_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:5972: undefined reference to `__gmpn_mul_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:5989: undefined reference to `__gmpn_submul_1'
/home/piotr/Downloads/ntl-9.6.2/src/g_lip_impl.h:6024: undefined reference to `__gmpn_mul_1'
collect2: error: ld returned 1 exit status
CMakeFiles/crypto.dir/build.make:225: polecenia dla obiektu 'crypto' nie powiodły się
make[2]: *** [crypto] Błąd 1
CMakeFiles/Makefile2:67: polecenia dla obiektu 'CMakeFiles/crypto.dir/all' nie powiodły się
make[1]: *** [CMakeFiles/crypto.dir/all] Błąd 2
Makefile:83: polecenia dla obiektu 'all' nie powiodły się
make: *** [all] Błąd 2

私のcmakeは次のようになります。

cmake_minimum_required(VERSION 2.8.9)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
project(crypto)

set(PROJECT_NAME "crypto")

find_package(NTL REQUIRED)

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread")
else()
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

SET(CMAKE_EXE_LINKER_FLAGS "-static -lntl -lgmpxx -lgmp -lm")

add_executable(crypto main.cpp elliptic_curve.cpp point.cpp lenstra.cpp pollard_algorithm.cpp ThreadPool.cpp)
target_link_libraries(crypto ${NTL_LIBRARY})

何が間違っているのか本当にわかりません。どんな助けにも感謝します。

アップデート:

gmp と ntl がインストールされています。

⋊> ~/D/gmp-6.1.0 ls ~/sw/lib/libntl.a        
/home/piotr/sw/lib/libntl.a
⋊> ~/D/gmp-6.1.0 ls /usr/local/lib/libgmp.a     
/usr/local/lib/libgmp.a
⋊> ~/D/gmp-6.1.0 ls /usr/local/lib/libgmpxx.a   
/usr/local/lib/libgmpxx.a

行を削除すると:

SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
SET(BUILD_SHARED_LIBRARIES OFF)
SET(CMAKE_EXE_LINKER_FLAGS "-static")

cmake から、コードを問題なく正常にコンパイルできます。しかし、サーバーでこのコードを実行するには静的コンパイルが必要ですが、現在のビルド設定ではこれが不可能です。理由はわかりません。

次のような適切な FindNTL.cmake ファイルもあります。

FIND_PATH(NTL_INCLUDE_DIR RR.h
  HINTS
  $ENV{NTLDIR}
  PATH_SUFFIXES NTL include/NTL include
  PATHS
  ~/sw #
)

FIND_LIBRARY(NTL_LIBRARY
  NAMES ntl
  HINTS
  $ENV{NTLDIR}
  PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64
  PATHS
  ~/sw
)


# handle the QUIETLY and REQUIRED arguments and set NTL_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(NTL DEFAULT_MSG  NTL_LIBRARY NTL_INCLUDE_DIR)

MARK_AS_ADVANCED(NTL_LIBRARY NTL_INCLUDE_DIR)

VERBOSE=1 にする

[ 14%] Linking CXX executable crypto
/usr/bin/cmake -E cmake_link_script CMakeFiles/crypto.dir/link.txt --verbose=1
/usr/bin/c++    -std=c++11 -pthread  -static -lntl -lgmpxx -lgmp -lm CMakeFiles/crypto.dir/main.cpp.o CMakeFiles/crypto.dir/elliptic_curve.cpp.o CMakeFiles/crypto.dir/point.cpp.o CMakeFiles/crypto.dir/lenstra.cpp.o CMakeFiles/crypto.dir/pollard_algorithm.cpp.o CMakeFiles/crypto.dir/ThreadPool.cpp.o  -o crypto -rdynamic /usr/local/lib/libntl.a 
4

1 に答える 1