How to use GMP with Cmake on CLion?
Answered
I did compile GMP in static and dynamic versions using this instruction: http://ethicorum.ru/?p=209&i=1&lang=ru. I got this files:
D:\Programs\ProgrammingEnvironment\Librares\gmp-6.1.1
├───bin
│ libgmp-10.dll
│ libgmpxx-4.dll
│
├───include
│ gmp.h
│ gmpxx.h
│
├───lib
│ libgmp.a
│ libgmp.dll.a
│ libgmp.la
│ libgmpxx.a
│ libgmpxx.dll.a
│ libgmpxx.la
│
└───share
└───info
dir
gmp.info
gmp.info-1
gmp.info-2
I try many times to use GMP but got "undefined reference", "cannot find -lgmp" errors.
Please help me to understand how to build project. My latest attempt:
cmake_minimum_required(VERSION 3.13)
project(Test_CLion)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17 -pedantic -Wall -Wextra -Wconversion")
set(STATIC_BUILD FALSE)
if (CMAKE_BUILD_TYPE MATCHES Release)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(STATIC_BUILD TRUE)
endif ()
if (STATIC_BUILD)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc")
endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Executable/bin)
set(ENV_ROOT "D:/Programs/ProgrammingEnvironment")
add_executable(${PROJECT_NAME} main.cpp)
set(GMP_DIR "${ENV_ROOT}/Librares/gmp-6.1.1")
include_directories(${PROJECT_NAME} ${GMP_DIR}/include)
find_library(GMP_LIBRARY NAMES gmp libgmp PATHS "${GMP_DIR}")
target_link_libraries(${PROJECT_NAME} gmp libgmp)
And I got "cannot find -lgmp"
Please sign in to leave a comment.
Hi!
Have you tried specifying the full path to the library? Like
Thanks! It work's! But I can use only dynamic linked GMP. How to make it static? I tryed this:
But I got
And then
Full CMakeLists.txt:
libgmp.a and libgmpxx.a are static libraries. If you remove -static-libgmpxx and do
does it work?
And using
will include the static libraries in the executable.
No, It did't work's. I do this:
And got this:
What toolchain do yo use in CLion? What toolchain did you use for building the GMP libraries?
mingw32-i686-8.1.0-release-posix-dwarf-rt_v6-rev0
https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z