linux 系统安装 or-tools 并在c++ 项目中使用

文章目录

    • [1. 系统环境](#1. 系统环境)
    • [2. 下载 OR-TOOLS 源码](#2. 下载 OR-TOOLS 源码)
    • [3. 编译安装 OR-TOOLS](#3. 编译安装 OR-TOOLS)
    • [4. 在 c++ 项目中使用 OR-TOOLS](#4. 在 c++ 项目中使用 OR-TOOLS)

1. 系统环境

Ubuntu-18.04

cmake-3.16

g+±9

2. 下载 OR-TOOLS 源码

Github:https://github.com/google/or-tools/releases

此处注意 ortools 较新的版本(9.6)需要 C++20 编译标准(cmake-3.18,G++10),虽然切换 cmake 和 G++ 版本很方便,但是会导致很多系统原有的代码无法编译通过,所以选择 ortools 9.1 版本。

切换 cmake 版本:https://blog.csdn.net/weixin_41010198/article/details/109343347

切换 gcc、g++ 版本:https://blog.csdn.net/u012969412/article/details/125388624

3. 编译安装 OR-TOOLS

官方 cmake 安装文档:https://github.com/google/or-tools/blob/v9.1/cmake/README.md

下载好源码压缩包(zip 格式或 tar.gz 格式)后,解压,并 cd 到解压出的文件夹,例如

sh 复制代码
unzip or-tools-9.1.zip
cd or-tools-9.1

然后开始 cmake 编译

sh 复制代码
# -DBUILD_DEPS:BOOL=ON 一定要加上,否则很多依赖库不会编译
cmake -S. -Bbuild  -DBUILD_DEPS:BOOL=ON
cmake --build build

最后将 ortools 安装到系统中

sh 复制代码
cd build
sudo make install

4. 在 c++ 项目中使用 OR-TOOLS

在 CMakeLists.txt 中根据以下形式使用 ortools

cpp 复制代码
cmake_minimum_required(VERSION 3.14)
project(myproj VERSION 1.0)

find_package(ortools CONFIG REQUIRED)

add_executable(myapp main.cpp)
target_link_libraries(myapp ortools::ortools)
相关推荐
我命由我1234516 分钟前
Linux - Linux/POSIX 路径斜杠折叠规则
linux·运维·服务器·android studio·android jetpack·android-studio·android runtime
姚不倒29 分钟前
Nginx 反向代理:5 种负载均衡策略与实战
运维·nginx·负载均衡
xx~t31 分钟前
嵌入式——Linux软件编程——网络1
linux·c语言·网络·vscode·网络协议
Uncertainty!!1 小时前
Linux 主机无法完成校园网认证排查记录:从 DHCP、ARP 到 Portal 认证流程分析
linux·运维·服务器
神威难绷泪1 小时前
Linux消息队列 & 共享内存 笔记
linux·消息队列·共享内存
其实防守也摸鱼1 小时前
权限提升与横向移动:从内网渗透到域控的完整技术图谱
运维·服务器·数据库·安全·github·copilot·渗透
代码方舟1 小时前
零信任架构实战:基于天远车辆估值构建自动化二手车评估网关
运维·人工智能·架构·自动化
bgy66662 小时前
从零上手 Docker,容器技术完整入门指南
运维·docker·容器
mounter6252 小时前
突破零停机演进:Linux 内核 Live Update Orchestrator (LUO) 架构设计与热升级演进
linux·服务器·linux kernel·kernel·kho·luo