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)
相关推荐
阿里云大数据AI技术1 小时前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
orion5719 小时前
Missing Semester Class1:course overview and introduction of shell
linux
apocelipes21 小时前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
SkyWalking中文站1 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
火车叼位1 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
小猿姐2 天前
唯品会大规模数据库云原生实践:基于 KubeBlocks 管理数千实例的统一运维之路
运维·elasticsearch·云原生
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac