Linking GMP Library into CLion

Completed

Hi, I installed GMP library into my Windows system with " C:/gmp" prefix by using these instructions. After that, i changed the contents of my "CMakeLists.txt" file with the contents below.

But I still get an error with "undefined reference" warning and I'm having trouble finding solutions about this on the web. Can you help me with this problem?

Thanks.

cmake_minimum_required(VERSION 3.6)
project(cs50)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp functions.cpp)
add_executable(cs50 ${SOURCE_FILES})

include_directories("C:/gmp/include")
target_link_libraries(cs50 "C:/gmp/lib/libgmp.a")

0
2 comments
Avatar
Permanently deleted user

Okay, it is fixed after changing the cmake.txt file into this;

 

cmake_minimum_required(VERSION 3.6)
project(cs50)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp functions.cpp)
add_executable(cs50 ${SOURCE_FILES})

include_directories(cs50 "C:/gmp/include")
target_link_libraries(cs50 gmp libgmp)
0
Avatar
Permanently deleted user

If you are on Windows and using Cygwin as your tool chain, start Cygwin Setup and grab to the bin and src for...

  • gmp: Library for arbitrary precision arithmetic
  • gmp-debuginfo: Debug into for gmp
  • libgmp-devel: Library for arbitrary precision arithmetic (development)
  • libgmp-doc: Library for arbitrary precision arithmetic (documentation)
  • libgmpxx4: Library for arbitrary precision arithmetic (C++ runtime

 

Let that download and install.

Now, in your CmakeLists.txt file add the line

set(CMAKE_C_FLAGS "-lgmp")

 

Now you'll be able to include and compile with #include <gmp.h>.

 

I hope this helps.

0

Please sign in to leave a comment.