macos 编译gmplib 及cmake配置

1.下载gmp文件  解压后

./configure –enable-cxx

make

make check

make install

2. 配置cmake

创建FindGMP.cmake 使用这个文件找到相关头文件和动态库

set(GMP_PREFIX "" CACHE PATH "path ")


find_path(GMP_INCLUDE_DIR gmp.h gmpxx.h 
    PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include )

find_library(GMP_LIBRARY NAMES gmp libgmp 
    PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib)


if(GMP_INCLUDE_DIR AND GMP_LIBRARY)
    get_filename_component(GMP_LIBRARY_DIR ${GMP_LIBRARY} PATH)
    set(GMP_FOUND TRUE)
endif()

if(GMP_FOUND)
   if(NOT GMP_FIND_QUIETLY)
      MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
   endif()
elseif(GMP_FOUND)
   if(GMP_FIND_REQUIRED)
      message(FATAL_ERROR "Could not find GMP")
   endif()
endif()

cmakelist中的内容

注意set CMAKE_MODULE_PATH 设置了cmake文件加载路径(不然找不到FindGMP.cmake文件)

cmake_minimum_required(VERSION 3.12)
project(For_dream)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(GMP REQUIRED)
add_executable(For_dream main.cpp)
target_link_libraries(For_dream gmp gmpxx)

 

你可能感兴趣的:(linux编程相关)