ubuntu源码编译安装cmake高版本、pybind11安装、crow使用

cmake安装部署

一、文件下载

bash 复制代码
# cmake 3.12
wget https://cmake.org/files/v3.12/cmake-3.12.0.tar.gz --no-check-certificate
# cmake 3.15
wget https://github.com/Kitware/CMake/releases/download/v3.15.0-rc4/cmake-3.15.0-rc4.tar.gz

二、编译安装(cmake 3.15为例)

bash 复制代码
1、tar -zxvf cmake-3.15.0-rc4.tar.gz
2、cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/cmake-3.15.0 ..
3、make  make install

三、环境配置

bash 复制代码
1、sudo mv /usr/bin/cmake /usr/bin/cmake-3.10
2、sudo ln -s /opt/cmake-3.15.0/bin/cmake /usr/bin/cmake

pybind11源码安装

一、pybind11部署

bash 复制代码
1、git clone https://github.com/pybind/pybind11.git
2、cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/pybind11 ..
3、make make install

source ~/.bashrc
# 添加系统环境变量
export PYBIND11_ROOT=/opt/pybind11
export CMAKE_PREFIX_PATH=$PYBIND11_ROOT:$CMAKE_PREFIX_PATH

二、项目工程

CMakeLists.txt文件配置

bash 复制代码
cmake_minimum_required(VERSION 3.15) #这个也可以不写
project(test) #定义工程名字

#如果想要指定找的python解释器,可以设置Python_ROOT_DIR路径,如下所示
#set (Python_ROOT_DIR "/home/ubuntu/anaconda3/envs/standard310")
#find_package(Python 3.10 COMPONENTS Interpreter Development REQUIRED)
#注意找Python包一定要放在pybind11之前,否则无法根据自己想要的版本进行正确链接

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
if(Python3_FOUND)
message(STATUS "Python3路径: ${Python3_EXECUTABLE}")
message(STATUS "头文件目录: ${Python3_INCLUDE_DIRS}")
message(STATUS "库文件路径: ${Python3_LIBRARIES}")
endif()

find_package(pybind11 REQUIRED HINTS /opt/conda/pybind11)
include_directories(${pybind11_INCLUDE_DIRS})

pybind11_add_module(pybind_test src/main.cpp)#重点

set_target_properties(pybind_test PROPERTIES 
LIBRARY_OUTPUT_NAME "test_so"  # 自定义基础名称
SUFFIX ".so"                      # 可选:统一后缀
)

mian.cpp

cpp 复制代码
#include <pybind11/pybind11.h>
#include <iostream>

void f()
{
std::cout << "hello world\n";
}

PYBIND11_MODULE(pybind_test, m)
{
m.doc() = "a stupid function, print hello world";
m.def("hello", &f, "print hello world");
}

python

python 复制代码
>>> import pybind_test
>>> pybind_test.hello()
hello world

crow使用

一、基础环境

bash 复制代码
sudo apt install build-essential
sudo apt-get install libasio-dev
sudo apt-get install libboost-dev libssl-dev
git clone https://github.com/CrowCpp/Crow.git
相关推荐
蒋星熠13 小时前
爬虫与自动化技术深度解析:从数据采集到智能运维的完整实战指南
运维·人工智能·爬虫·python·深度学习·机器学习·自动化
迎風吹頭髮14 小时前
UNIX下C语言编程与实践19-UNIX 三级索引结构:直接索引、一级/二级/三级间接索引的文件存储计算
运维·云计算·unix
数智顾问14 小时前
AI自动化测试:接口测试全流程自动化的实现方法——从需求到落地的全链路实践
运维·人工智能·自动化
tt55555555555515 小时前
Linux 驱动开发入门:LCD 驱动与内核机制详解
linux·运维·驱动开发
行者..................15 小时前
petalinux 安装Armadillo
linux·运维·服务器
xiatianit15 小时前
【centos生产环境搭建(三)jdk环境配置】
linux
zhaotiannuo_199815 小时前
linux centos 7 解决终端提示符出现-bash-4.2的问题
linux·centos·bash
wangjialelele15 小时前
OSI模型、网络地址、与协议
linux·服务器·网络·tcp/ip
何中应15 小时前
CentOS安装Jenkins
linux·centos·jenkins
不枯石16 小时前
Matlab通过GUI实现点云的ICP配准
linux·前端·图像处理·计算机视觉·matlab