• mac下使用clion构建boost库


    mac下使用clion构建boost

    使用brew install boost

    完成后发现boost被安装在在/usr/local/Cellar/boost

    jetbrain给出的指导意见

    https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html

    ==================

    =============

    http://blog.csdn.net/to_be_better/article/details/53967198

    自己设定boost头文件和库文件位置

    -

    cmake_minimum_required(VERSION 3.6)

     

    #设置项目名称

    project(demo)

     

    set(CMAKE_CXX_STANDARD 11)

     

    set(BOOST_ROOT "/usr/local/include/boost")

     

    #添加头文件搜索路径

    include_directories(/usr/local/include)

     

    #添加库文件搜索路径

    link_directories(/usr/local/lib)

     

    #用于将当前目录下的所有源文件的名字保存在变量 DIR_SRCS 中

    aux_source_directory(. DIR_SRCS)

     

    add_executable(demo ${DIR_SRCS})

     

    #在这里根据名字boost_thread去寻找libboost_thread.a文件

    target_link_libraries(demo boost_thread boost_system)

    ==============

    =============

    https://stackoverflow.com/questions/28761323/how-to-include-external-library-boost-into-clion-c-project-with-cmake

    让Clion自动寻找

    cmake_minimum_required(VERSION 2.8.4)

     

    project(BoostTest)

     

    message(STATUS "start running cmake...")

     

    find_package(Boost 1.57.0 COMPONENTS system filesystem REQUIRED)

     

    if(Boost_FOUND)

     

        message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")

        message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")

        message(STATUS "Boost_VERSION: ${Boost_VERSION}")

     

        include_directories(${Boost_INCLUDE_DIRS})

     

    endif()

     

    add_executable(BoostTest main.cpp)

     

    if(Boost_FOUND)

     

        target_link_libraries(BoostTest ${Boost_LIBRARIES})

     

    endif()

    ===========

    =============

    mac下从源码编译boost库文件

    下载boost
    点击链接下载boost_1_61_0.tar.bz2 

    解压

    tar jxvf boost_1_61_0.tar.bz2

    运行bootstrap.sh脚本

    sh bootstrap.sh

    编译boost

    ./b2

    输出说明
    编译完成后

    • 头文件在当前目录下的boost中。
    • lib库在stage/lib

    作者:byd913

    链接:http://www.jianshu.com/p/7ab8ac4cb0ad

    來源:简书

    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

     

    另外可以参考这里

     http://www.cnblogs.com/linjk/p/6052886.html

     

    =============

    =============

    这里有一个完整的CMakeList.txt文件的编写方法

    http://blog.csdn.net/pyang1989/article/details/41725747

     

    1.写好cpp文件
    2.写CmakeList.txt,注意里面
    set(BOOST_COMPONENTS IOStreams Thread Filesystem Regex Serialization Signals System Timer)
    find_package(Boost 1.57.0 COMPONENTS ${BOOST_COMPONENTS})
    IOStreams Thread之类均为Boost的各个组件,完整的在lib目录下,例如libboost_iostreams.a 则iostreams则为组件名,不区分大小写。这里配置不正确的话,cmake能通过,make的时候出错Undefined symbols for architecture x86_64

    完整CmakeList.txt

    cmake_minimum_required (VERSION 2.6)

     

    project(Boost)

    add_executable(Boost Boost.cpp)

     

    set(Boost_INCLUDE_DIRS “/Users/yang/DEVELOPMENT/ProgramFiles/Boostinstallation/include”)

    set(Boost_LIBRARIES “/Users/yang/DEVELOPMENT/ProgramFiles/Boostinstallation/lib”)

    set(BOOST_COMPONENTS IOStreams Thread Filesystem Regex Serialization Signals System Timer)

     

    set(Boost_USE_STATIC_LIBS ON) 

    set(Boost_USE_MULTITHREADED ON) 

    set(Boost_USE_STATIC_RUNTIME OFF) 

    find_package(Boost 1.57.0 COMPONENTS ${BOOST_COMPONENTS})

     

    if(Boost_FOUND)

    include_directories(${Boost_INCLUDE_DIRS}) 

    target_link_libraries(Boost ${Boost_LIBRARIES}) 

    endif()

     

     

    这样便可以依次执行cmake和make命令生成可执行应用程序了。

     

    ================

    ===============

    我的可以运行的例子:

     

    cmake_minimum_required(VERSION 3.6)
    project(boost_All)

    message(STATUS "start running cmake...")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    include_directories(./client_asio)
    include_directories(./server_asio)

    set(SOURCE_FILES server_asio/main.cpp)
    add_executable(boost_All ${SOURCE_FILES})

    set(Boost_INCLUDE_DIR /Users/lizhen/src_github/boost_1_65_1/)
    #set(boost_LIBRARIES /Users/lizhen/src_github/boost_1_65_1/stage/lib)
    set(Boost_COMPONENTS Thread Filesystem Regex Serialization Signals System Timer REQUIRED)

    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_USE_STATIS_RUNTIME OFF)

    find_package(Boost COMPONENTS ${Boost_COMPONENTS})
    if (Boost_FOUND)
    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")
    include_directories(${Boost_INCLUDE_DIR})
    target_link_libraries(boost_All ${Boost_LIBRARIES})
    endif()

     

  • 相关阅读:
    D2. Remove the Substring (hard version)(思维 )
    暑假集训
    AcWing:167. 木棒(dfs + 剪枝)
    AcWing:109. 天才ACM(倍增 + 归并排序)
    AcWing:99. 激光炸弹(前缀和)
    B. Interesting Array(线段树)
    Best Reward HDU
    G. Swapping Places
    How many HDU
    GSS4&&花仔游历各国
  • 原文地址:https://www.cnblogs.com/li-daphne/p/7588552.html
Copyright © 2020-2023  润新知