0

So I have a project, and I need to use the GMP library to generate really big numbers.

In my project I made a lib/ dir, which contains another dir, gmp/. In that directory my 2 header files gmp.h and gmpxx.h are placed.

I added those header files to my CMakeLists.txt, like this

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})

But for some reason, when including gmpxx.h, and actually using something from it I get this when building:

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

What causes this?

David
  • 29
  • 1
  • Welcome to Stack Overflow. Please take the time to read [The Tour](http://stackoverflow.com/tour) and refer to the material from the [Help Center](http://stackoverflow.com/help/asking) what and how you can ask here. – πάντα ῥεῖ May 20 '17 at 19:38
  • Thanks, I could not find that thread – David May 20 '17 at 19:40

0 Answers0