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)
相关推荐
程序猿(雷霆之王)6 分钟前
Linux——冯 • 诺依曼体系结构&操作系统初识
linux·运维·服务器
宁zz21 小时前
乌班图安装jenkins
运维·jenkins
懒羊羊大王&1 天前
模版进阶(沉淀中)
c++
大丈夫立于天地间1 天前
ISIS协议中的数据库同步
运维·网络·信息与通信
cg50171 天前
Spring Boot 的配置文件
java·linux·spring boot
暮云星影1 天前
三、FFmpeg学习笔记
linux·ffmpeg
owde1 天前
顺序容器 -list双向链表
数据结构·c++·链表·list
rainFFrain1 天前
单例模式与线程安全
linux·运维·服务器·vscode·单例模式
GalaxyPokemon1 天前
Muduo网络库实现 [九] - EventLoopThread模块
linux·服务器·c++
W_chuanqi1 天前
安装 Microsoft Visual C++ Build Tools
开发语言·c++·microsoft