linux下基於官方原始碼編譯ipopt
1、C++依賴項安裝升級
由於需要編譯c++所以需要安裝一系列的依賴:
apt-get update
apt-get -y upgrade
apt install build-essential
apt-get install -y gcc g++ gfortran git patch wget pkg-config liblapack-dev libmetis-dev libblas-dev vim
2、下載需要編譯的程式碼檔案
總共有5個重要的檔案包:
1. Ipopt :https://github.com/coin-or/Ipopt.git
2. ThirdParty-ASL : https://github.com/coin-or-tools/ThirdParty-ASL.git
3. ThirdParty-HSL : https://github.com/coin-or-tools/ThirdParty-HSL.git
4. ThirdParty-Mumps : https://github.com/coin-or-tools/ThirdParty-Mumps.git
5. coinhsl.zip : 為ThirdParty-HSL編譯的依賴項,其官網為: [Coin-HSL available from STFC IP Store](https://licences.stfc.ac.uk/product/coin-hsl) ,該檔案下載比較麻煩且很難查詢的到
3、編譯檔案
-
編譯ThirdParty-ASL
cd ThirdParty-ASL || exit ./get.ASL ./configure make make install
-
編譯ThirdParty-HSL
-
將coinhsl.zip解壓到ThirdParty-HSL
cp coinhsl.zip ThirdParty-HSL cd ThirdParty-HSL || exit unzip coinhsl.zip
-
編譯
./configure make make install
-
-
編譯ThirdParty-Mumps
cd ThirdParty-Mumps || exit ./get.Mumps ./configure make make install
-
編譯Ipopt
cd Ipopt || exit mkdir build cd build || exit ../configure make make test make install
4、配置環境變數
cd /usr/local/include || exit
cp coin-or coin -r
ln -s /usr/local/lib/libcoinmumps.so.3 /usr/lib/libcoinmumps.so.3
ln -s /usr/local/lib/libcoinhsl.so.2 /usr/lib/libcoinhsl.so.2
ln -s /usr/local/lib/libipopt.so.3 /usr/lib/libipopt.so.3
echo "Add the/usr/local/lib directory to the configuration file of the shared library"
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
5、一鍵式操作指令碼
- 預先下載檔案:夸克連結:https://pan.quark.cn/s/8928a21eaf0b
- 在資料夾Ipopt_pkg下,存放提供的兩個壓縮檔案:coinhsl.zip ; Ipopt_pkg.zip
- 在Ipopt_pkg資料夾的同級地址下執行指令碼depoly_ipopt.sh
檔案結構樹:
-- Ipopt_pkg
- coinhsl.zip
- Ipopt_pkg.zip
-- depoly_ipopt.sh
depoly_ipopt.sh :
#!/bin/bash
echo "Compile ipopt and dependencies:" # echo is used to printf in terminal
echo "dependencies: gcc g++ gfortran git patch wget pkg-config liblapack-dev libmetis-dev libblas-dev"
apt-get update
apt-get -y upgrade
apt install build-essential
apt-get install -y gcc g++ gfortran git patch wget pkg-config liblapack-dev libmetis-dev libblas-dev vim
echo "===========================dependencies: over====================================="
if [ ! -d "/Ipopt_pkg" ]; then
mkdir /Ipopt_pkg
fi
cd Ipopt_pkg || exit
unzip Ipopt_pkg.zip
echo "===========================make ASL==========================="
if [ ! -d "/ThirdParty-ASL" ]; then
git clone https://github.com/coin-or-tools/ThirdParty-ASL.git
fi
cd ThirdParty-ASL || exit
./get.ASL
./configure
make
make install
cd ..
echo "===========================make HSL==========================="
if [ ! -d "/ThirdParty-HSL" ]; then
git clone https://github.com/coin-or-tools/ThirdParty-HSL.git
fi
if [ ! -d "/ThirdParty-HSL/coinhsl.zip" ]; then
cp coinhsl.zip ThirdParty-HSL # 將預先下載好的線性求解器編譯檔案壓縮包新增到資料夾ThirdParty-HSL內
fi
cd ThirdParty-HSL || exit
unzip coinhsl.zip
./configure
make
make install
cd ..
echo "===========================make Mumps==========================="
if [ ! -d "/ThirdParty-Mumps" ]; then
git clone https://github.com/coin-or-tools/ThirdParty-Mumps.git
fi
cd ThirdParty-Mumps || exit
./get.Mumps
./configure
make
make install
cd ..
echo "===========================make Ipopt==========================="
if [ ! -d "/Ipopt" ]; then
git clone https://github.com/coin-or/Ipopt.git
fi
cd Ipopt || exit
mkdir build
cd build || exit
../configure
make
make test
make install
echo "===========================Improve the environment==========================="
cd /usr/local/include || exit
cp coin-or coin -r
ln -s /usr/local/lib/libcoinmumps.so.3 /usr/lib/libcoinmumps.so.3
ln -s /usr/local/lib/libcoinhsl.so.2 /usr/lib/libcoinhsl.so.2
ln -s /usr/local/lib/libipopt.so.3 /usr/lib/libipopt.so.3
echo "Add the/usr/local/lib directory to the configuration file of the shared library"
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
echo "===========================Compile ipopt and dependencies: over!==========================="