windows环境下cmake配置or-tools环境

    最近需要用第三方的开源代码,在python里面调用线性优化求解器。google公司的开源代码or-tools可以支持第三方求解器。在配置环境的过程中,遇到了各种各样的bug,虽然官方教程很规范,但缺乏对于这些报错的处理方式,所以在这里写一篇简单的教程,记录一下如何配置环境。

  • SCIP Optimization Suite

  • CPLEX

  • GLPK

  • Gurobi

====================

    第一步,需要x64位的操作系统,虽然不确定win7能不能使用,但是win10的安装是没有问题的。

    第二步,需要安装VS2019,家庭版或者企业版都可以。这里有个很重要的点,就是很多报错时需要的插件其实并不需要。在VS2019中,有一个专门用于cmake的C、C++组件,安装这个即可。另外windows10 SDK也需要安装,不然在使用cmake GUI的时候,很容易报错找不到需要的文件。(注意,使用cmake编译的过程中,对于VS版本以及安装位置有严格的验证过程,如果版本不一致,会报错。卸载VS可以使用installCleanup.exe。)

    第三步,常规的软件安装,需要安装git、python、cmake,三个文件都不大,几十MB。

    这个过程中要注意一下pip的版本号,最好更新为最新的版本。python和cmake安装完成后会自动在windows的环境变量中添加path,所以可以直接在命令行模式下运行python和make指令。

python --version;显示python版本号
python -m pip --version;显示pip版本号
python -m pip install --upgrade pip;升级pip版本

    第四步,安装https://github.com/google/or-tools,下载代码的时候会遇到一个问题,速度非常慢。整个代码包一共1.6G

    解决方法是使用第三方的网站http://gg.widyun.com/进行代理,将代码链接输入后,点击后可以生成压缩文件,下载速度快很多。

    第五步,运行 x64 Native Tools Command Prompt进入命令行模式(注意不是CMD模式,这点非常重要),该命令行模式快捷方式在VS2019的MSVC组件里,进入到or-tools目录夹下(注意,不能有中文路径名,建议放在根目录下)。运行指令激活第三方插件功能。

tools\make third_party
  如果,VS2019版本一致,安装目录规范;代码下载完整,无损坏文件。这个阶段应该会顺利编译完成。速度非常慢,因为从github上下载代码,耐心等待就可以了。到这一步,环境配置的第一道难关就算结束了

    第六步,安装第三方优化求解器,并在cmake配置文件中加入求解器路径。在or-tools的主目录下面有一个Makefile.local的文件,使用文本编辑器打开(推荐notepad++),在文件尾部添加:

WINDOWS_SCIP_DIR=c:/Program Files/SCIPOptSuite
 这里是以SCIP为例,等号后面的部分为你安装求解器的实际路径名。

    第七步,使用cmake编译or-tools代码

tools\make python
 第八步,测试环境配置是否正确
tools\make test_python
  之前在这一步出现报错,后来发现是某个源文件的编码模式不一致,仍然使用的ASCII编码,而不是Unicode。在ASCII中的“?”变成了Unicode的“□”。后来单独把文件复制出来,转换编码后修复该bug。到test_python完成,环境配置的第二道难关就算结束了

    如果测试编译不通过,可以使用指令清除文件重新编译。

tools\make clean_third_party

tools\make third_party

tools\make python

    第九步,将编译完成的第三方优化求解器代码加载到python的环境中,使用如下指令:

tools\make install_python
  通过该指令,包含第三方优化求解器的or-tools代码加载到python环境中,可以使用import的方式进行调用。

    至此,在windows环境下,使用cmake编译器编译第三方优化求解器到python开发环境的配置就完成了。

==========================

我是龙翔可乐

一个喜欢摄影的计算机老师

### ESP-IDF Framework Installation Guide and Environment Setup Instructions For developing applications for ESP32 using the C language, setting up the toolchain on one’s personal computer is essential. The process involves installing the ESP-IDF (Espressif IoT Development Framework), which includes all necessary components such as compilers, libraries, and tools required for development[^1]. #### Prerequisites Before starting with the installation of ESP-IDF, ensure that certain prerequisites are met: - Operating System: Linux, macOS, or Windows. - Python version 3.6 or above installed. #### Installing Dependencies On Linux systems, several dependencies need to be installed first via package managers like `apt`: ```bash sudo apt-get update sudo apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 ``` #### Downloading ESP-IDF The next step involves downloading ESP-IDF from Espressif’s official GitHub repository: ```bash git clone --recursive https://github.com/espressif/esp-idf.git cd esp-idf ./install.sh source ./export.sh ``` This script installs additional packages needed by ESP-IDF and sets up environment variables permanently within the current terminal session. For future sessions, executing `source $IDF_PATH/export.sh` will set these variables again. #### Verifying Installation To verify whether everything has been correctly configured, create an example project provided alongside ESP-IDF: ```bash idf.py create-project hello_world cd hello_world idf.py build flash monitor ``` These commands compile the code into firmware images suitable for flashing onto the ESP32 module over USB serial connection while also opening a serial console window where output can be observed during execution. --related questions-- 1. What specific versions of software should users have when preparing their system? 2. Can this setup procedure apply equally well across different operating systems? 3. Are there any common pitfalls encountered during the configuration phase? 4. How does one troubleshoot issues related to failed builds after following these steps?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值