所以我有一个项目,我需要使用GMP库来生成非常大的数字。
在我的项目中,我创建了一个lib/
目录,其中包含另一个目录gmp/
。在该目录中,我放置了2个头文件gmp.h
和gmpxx.h
。
我将这些头文件添加到我的CMakeLists.txt中,就像这样
cmake_minimum_required(VERSION 3.7)
project(Crypto)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES
src/main.cpp
src/DavidCrypto.cpp
src/DavidCrypto.h
src/RSA.cpp
src/RSA.h
lib/gmp/gmpxx.h
lib/gmp/gmp.h
)
add_executable(Crypto ${SOURCE_FILES})
但出于某种原因,当包括gmpxx.h
并实际使用其中的某些内容时,我会在构建时获得此内容:
CMakeFiles/Crypto.dir/src/RSA.cpp.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::assign_ui(unsigned long)':
/home/david/code/c++/Crypto/src/../lib/gmp/gmpxx.h:1441: undefined reference to `__gmpz_set_ui'
CMakeFiles/Crypto.dir/src/RSA.cpp.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr()':
/home/david/code/c++/Crypto/src/../lib/gmp/gmpxx.h:1488: undefined reference to `__gmpz_init'
CMakeFiles/Crypto.dir/src/RSA.cpp.o: In function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr()':
/home/david/code/c++/Crypto/src/../lib/gmp/gmpxx.h:1523: undefined reference to `__gmpz_clear'
collect2: error: ld returned 1 exit status
CMakeFiles/Crypto.dir/build.make:146: recipe for target 'Crypto' failed
make[3]: *** [Crypto] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Crypto.dir/all' failed
make[2]: *** [CMakeFiles/Crypto.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/Crypto.dir/rule' failed
make[1]: *** [CMakeFiles/Crypto.dir/rule] Error 2
Makefile:118: recipe for target 'Crypto' failed
make: *** [Crypto] Error 2
是什么导致这种情况?