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)
相关推荐
君穆南14 分钟前
基于 NFS 与 Rsync 实现跨服务器 Seafile 数据平滑迁移实战
linux·运维·git
bloglin9999917 分钟前
scp、rsync远程文件同步
linux·运维·服务器
迦南的迦 亚索的索27 分钟前
LINUX环境
linux·运维·服务器
yuanjj8829 分钟前
linux下调试域格CLM920 NC5等9x07平台模块 QMI拨号
linux·运维·服务器
IMPYLH1 小时前
Linux 的 printenv 命令
linux·运维·服务器·bash
SilentSamsara1 小时前
SSH 远程管理:密钥登录 + 隧道转发,一次性配置好
linux·运维·服务器·ubuntu·centos·ssh
LN花开富贵1 小时前
【ROS】鱼香ROS2学习笔记一
linux·笔记·python·学习·嵌入式·ros·agv
疏星浅月1 小时前
数据对齐的底层原理与性能优化
linux
Jurio.1 小时前
本机开发 + 多机执行的极简远端运行工具
linux·git·python·github·远程工作
t***5442 小时前
如何在现代C++中更有效地应用这些模式
java·开发语言·c++