• Boost Python学习笔记(一)


    开发环境搭建

    下载源码

    boost_1_66_0.tar.gz

    生成编译工具

    # tar axf boost_1_66_0.tar.gz
    # cd boost_1_66_0
    # yum install gcc gcc-c++ python-devel cmake -y
    # ./bootstrap.sh
    

    编译32位boost库

    # ./b2 install --with-system --with-thread --with-date_time --with-regex --with-serialization --with-python link=shared runtime-link=shared threading=multi debug
    

    设置boost动态库加载路径

    # tee /etc/ld.so.conf.d/boost-x86_64.conf << EOF
    /usr/local/lib
    EOF
    # ldconfig
    

    项目目录结构

    项目初始目录结构样例

    [root@fcloud example]# tree .
    .
    ├── build
    ├── CMakeLists.txt
    ├── include
    │   └── header.h
    ├── main.cpp
    └── src
        └── header.cpp
    
    3 directories, 4 files
    

    CMake样例(编译后将生成两个文件,一个可执行文件core,一个动态库boost.so)

    cmake_minimum_required(VERSION 2.8)
    project(boost)
    
    set(CMAKE_CXX_FLAGS  "-Wall -g")
    
    ### 此处的动态库名必须和BOOST_PYTHON_MODULE()中定义的保持一致,即最后生成的库必须名为boost.so
    file(GLOB SRC "src/*.cpp")
    add_library(boost SHARED ${SRC})
    add_executable(core main.cpp)
    set_target_properties(boost PROPERTIES PREFIX "")
    
    #dependencies
    INCLUDE(FindPkgConfig)
    pkg_check_modules(PYTHON REQUIRED python)
    include_directories(include /usr/local/include ${PYTHON_INCLUDE_DIRS})
    link_directories(/usr/local/lib ${PYTHON_LIBRARY_DIRS})
    target_link_libraries(boost boost_python)
    target_link_libraries(core boost ${PYTHON_LIBRARIES})
    
  • 相关阅读:
    centos7系统初始化脚本
    git上传项目到github
    requests的使用
    zip函数
    mongodb基本操作
    mongodb的安装与配置启动(转)
    jupyter插件与主题
    map函数
    centos7 安装 ffmpeg
    centos7 下 yum 安装Nginx
  • 原文地址:https://www.cnblogs.com/silvermagic/p/9087490.html
Copyright © 2020-2023  润新知