C ++: Boost library installed on your Mac and use CLion development

1. Download and install the Boost library

Official website to download the latest version 1.65.0: http://www.boost.org/users/history/version_1_65_0.html
select UNIX version:

img

Cd download, unzip to extract the folder

cd /Users/jimmy/Downloads/boost_1_65_0

carried out

./booststrap.sh

After successful execution

sudo ./b2 install

After a few minutes to compile and install complete
header file is located in / usr / local / include / boost
library path is located in / usr / local / lib

2. Use

Use CLion create a new C ++ project
Project name: TTT
CMakeList.txt
CMake to look up connection on the Boost libraries, or else the compiler will complain, can not find boost

cmake_minimum_required(VERSION 3.8)
project(ttt)

set(CMAKE_CXX_STANDARD 11)

find_package(Boost 1.65.0 COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

set(SOURCE_FILES main.cpp)
add_executable(ttt ${SOURCE_FILES})

target_link_libraries(ttt ${Boost_LIBRARIES})

main.cpp
the include a header file must be specified boos

#include <iostream>
#include <boost/version.hpp>

using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    cout << "Boost版本:" << BOOST_VERSION << endl;
    return 0;
}

execution succeed

img

3. The following are two methods to compile

3.1 set their own boost header and library files location

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)

3.2 Let Clion automatically find

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()

Guess you like

Origin www.cnblogs.com/kolane/p/12071055.html
Recommended