0

I put the gmpxx.h and gmp.h files into the folder ./proj/include/gmp and I include them into files located at path ./proj/src/file.cpp or ./proj/test/test.cpp.

This is the content of my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.18)

enable_language(CXX)

set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)

SET(CMAKE_CXX_FLAGS  "-pedantic -Wall -Wextra -lgmpxx -lgmp")

include(CMakeToolsHelpers OPTIONAL)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 20)

include_directories(include/gmp)

But, when I try to build the project the compiler return me this error:

ld: library not found for -lgmpxx

collect2: error: ld returned 1 exit status

I also tried to install directly the library but the installation faild. How can I fix the problem?

th3g3ntl3man
  • 1,926
  • 5
  • 29
  • 50
  • You `find_library` fills the variable `GMP_LIBRARY` with path to the library. So you need to use this variable in linking with the library. Note, that linking is performed with `target_link_libraries` command. – Tsyvarev Nov 19 '20 at 21:49
  • @Tsyvarev Sorry, this is just a test. I update the question with my actual content file. You can give me an practical example? – th3g3ntl3man Nov 19 '20 at 21:59
  • If you know the path to the `gmpxx` **library**, then you may pass it to `target_link_libraries` call. See [that question](https://stackoverflow.com/questions/8774593/cmake-link-to-external-library) for more details. If you don't know whether the library is installed or not... then you need to install it first, before writting `CMakeLists.txt`. – Tsyvarev Nov 19 '20 at 22:42
  • 2
    Finding a library specified with a `-l` option has nothing to do with header files. So the first sentence of your question is not relevant. – JaMiT Nov 19 '20 at 23:23

0 Answers0