I am trying to configure GMP on CLion (Apple Silicon), for use in my C++ programmes, and have the following CMakeLists.txt:
project(cs50)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
find_package(GMP REQUIRED)
add_executable(Turrial main.cpp)
target_link_libraries(Turrial gmp gmpxx)
It seems like I need a FindGMP.cmake file too, as the error when I load the CMake changes is:
CMake Error at CMakeLists.txt:5 (find_package):
By not providing "FindGMP.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "GMP", but
CMake did not find one.
Could not find a package configuration file provided by "GMP" with any of
the following names:
GMPConfig.cmake
gmp-config.cmake
Add the installation prefix of "GMP" to CMAKE_PREFIX_PATH or set "GMP_DIR"
to a directory containing one of the above files. If "GMP" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/Users/mikaelbashir/CLionProjects/cs50/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/Users/mikaelbashir/CLionProjects/cs50/cmake-build-debug/CMakeFiles/CMakeError.log".
[Failed to reload]
I've looked at many sources online, and the closest thing to what I (think I) need is for C programmes at [https://stackoverflow.com/questions/29307862/error-linking-gmp-library/29309437#29309437], so I don't know if the FindGMP.cmake file needs to be modified or not, or how to tell CmakeLists.txt where to find it. I installed GMP using homebrew, and the related files I have are:
/opt/homebrew/Cellar/gmp/6.2.1_1/include/ (2 files)
/opt/homebrew/Cellar/gmp/6.2.1_1/lib/libgmp.10.dylib
/opt/homebrew/Cellar/gmp/6.2.1_1/lib/libgmpxx.4.dylib
/opt/homebrew/Cellar/gmp/6.2.1_1/lib/pkgconfig/ (2 files)
/opt/homebrew/Cellar/gmp/6.2.1_1/lib/ (4 other files)
/opt/homebrew/Cellar/gmp/6.2.1_1/share/info/ (3 files)
My question is, how can I fix this error so that GMP is correctly configured in my project. Please be as specific as possible, as I am relatively bad at programming and new to C++.
I tried many different CMakeLists.txt files but none seem to be working. The one I mentioned at least allows CLion to find <gmpxx.h>, but still I am struggling to get CLion to configure GMP.
That pkgconfig
directory contains pkg-config files, which contain information for the compiler.
In CMake you can use the FindPkgConfig
module to interpret these files for you and create a CMake-native target you can link to:
find_package(PkgConfig REQUIRED)
pkg_check_modules(GMPXX REQUIRED IMPORTED_TARGET gmpxx)
target_link_libraries(Turrial PkgConfig::GMPXX)