MinGW编译Boost库可以参考我之前写的编译Boost的文章。
以下是cmake链接boost静态库的配置:
1 cmake_minimum_required(VERSION 3.8) 2 3 project(clions) 4 5 set(CMAKE_CXX_STANDARD 14) 6 set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/Install CACHE PATH "Install here" FORCE) 7 8 set (Boost_USE_STATIC_LIBS ON) # enable dynamic linking 9 set (Boost_USE_MULTITHREAD ON) # enable multithreading 10 11 # windows 下设置这两个路径,find_package才能找到Boost 12 SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "D:/MathxH/3rd-party/boost_1_67_0/bin/static/include/boost-1_67") 13 SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "D:/MathxH/3rd-party/boost_1_67_0/bin/static/lib") 14 15 16 17 find_package(Boost) 18 19 if(NOT Boost_FOUND) 20 message("not found boost package") 21 else() 22 message("found boost package") 23 include_directories(${Boost_INCLUDE_DIR}) 24 LINK_DIRECTORIES(${CMAKE_LIBRARY_PATH}) 25 ## ADD_DEFINITIONS("-DHAS_BOOST") 26 27 message("includes: ${Boost_INCLUDE_DIRS}") # 这个可以打印出值来 28 message("libs: ${Boost_LIBRARIES}") #这个变量在windows下找不到,为空 29 endif() 30 31 if(USE_32BITS) 32 message("build x86 target") 33 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") 34 else() 35 message("build x64 target") 36 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") 37 endif(USE_32BITS) 38 39 add_executable(clions main.cpp) 40 41 if(Boost_FOUND) 42 43 if(CMAKE_BUILD_TYPE MATCHES "Debug") 44 message("linking debug lib") 45 target_link_libraries(clions libboost_filesystem-mgw81-mt-sd-x64-1_67.a libboost_system-mgw81-mt-sd-x64-1_67.a) 46 endif() 47 48 if(CMAKE_BUILD_TYPE MATCHES "Release") 49 message("linking release lib") 50 target_link_libraries(clions libboost_filesystem-mgw81-mt-s-x64-1_67.a libboost_system-mgw81-mt-s-x64-1_67.a) 51 endif() 52 53 endif() 54 55 install(TARGETS clions DESTINATION debug CONFIGURATIONS Debug) 56 install(TARGETS clions DESTINATION release CONFIGURATIONS Release)
如果配置好Clion的ToolChain,它会自动运行以下cmake命令行,生成makefile:
cmake.exe -DCMAKE_BUILD_TYPE=Release -DUSE_32BITS=0 -DBOOST_ROOT=D:\MathxH\3rd-party\boost_1_67_0\bin\static -DBOOST_LIBRARYDIR=D:\MathxH\3rd-party\boost_1_67_0\bin\static\lib -G "CodeBlocks - MinGW Makefiles" D:\clions
原文地址:https://www.cnblogs.com/foohack/p/9397768.html
时间: 2024-09-29 14:16:14