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)
相关推荐
高梦轩4 小时前
MySQL高可用
android·运维·数据库
hsjcjh7 小时前
Nodemailer使用教程:在Node.js中发送电子邮件
linux·运维·node.js
没有梦想的咸鱼185-1037-16638 小时前
北斗高精度数据解算:破解城市峡谷/长基线/无网区难题,从毫米级定位到自动化交付——(GAMIT/GLOBK底层核心解算技术方法)
运维·arcgis·数据分析·自动化
不怕犯错,就怕不做8 小时前
linux 如何查看自己的帐号密码及samba的帐号和密码
linux·运维·服务器
实在智能RPA8 小时前
Agent 在物流行业能实现哪些自动化?——深度拆解 AI Agent 驱动的智慧物流新范式
运维·人工智能·ai·自动化
地下核武8 小时前
Ubuntu 24.04 在线安装 Qt 6.10.2 后 Qt Creator 无法启动问题记录与解决
linux·qt·ubuntu
张3239 小时前
Linux 启动过程
linux·运维
三万棵雪松9 小时前
【Linux 物联网网关主控系统-Linux主控部分(二)】
linux·嵌入式linux
chinesegf9 小时前
ubuntu建虚拟环境制作docker容器
linux·ubuntu·docker
Stack Overflow?Tan909 小时前
标注软件labelImg在linux下鼠标滚轮闪退解决办法
linux·labelimg