Linux下用Intel編譯器編譯安裝NetCDF-Fortan庫(4.2版本後)

來源:互聯網
上載者:User

標籤:style   class   blog   code   http   tar   

本來這個問題真的沒必要寫的,可是真的困擾我太久%>_<%,決定還是記錄一下。

首先,最權威清晰的安裝文檔還是官方的:

Building the NetCDF-4.2 and later Fortran libraries (寫此文時,最近版為4.2)

那這個文檔最開始就告訴我們,自NetCDF庫4.2版本以後,Fortran的庫和C的庫就要分開build啦!而且要裝Fortran的庫必須先裝好C的庫。

所以先裝C的庫咯:仍然官方文檔:

Getting and Building NetCDF-C (寫此文時,最新版本為4.3.2)

那這個文檔告訴我們:要裝NetCDF-C的庫,有三個(其實是兩個)必須裝的:zlib,HDF5,(curl)。

綜上,需要下載4個tar的包。點我們下載:zilb & hdf5  netcdf-c-4.3.2  netcdf-fortran-4.2

參照官方文檔,zlib和hdf5的安裝比較簡單,指定一下安裝路徑即可:

build zlib:

$ ./configure --prefix=/home/ed/local$ make check install

build HDF5:

$ ./configure --with-zlib=/home/ed/local --prefix=/home/ed/local $ make check install

其中,比較容易出問題的是HDF5的安裝,參閱HDF5官方文檔

成功之後,就可以進行netcdf-c和netcdf-fortran庫的安裝了,這裡有個問題要注意:編譯安裝庫時候的編譯器要和你以後編譯你的Fortran代碼使用的編譯器一致,否者以後在編譯Fortran原始碼其中用到netcdf庫時會出錯。以我為例:我平時用Intel的編譯器,所以此時在安裝這兩個庫的時候,分別用Intel C++ Composer和Intel Fortran Composer進行編譯(後面簡稱icc和ifort)

Intel 編譯器的

User and Reference Guide for the Intel® C++ Compiler 14.0

User and Reference Guide for the Intel® Fortran Compiler 14.0

Using Intel Compilers for Linux Under Redhat Enterprise Linux or CentOS

安裝好了icc和ifort以後均需要設定一下環境變數:(最好添加到~/.bashrc檔案中)

source <compiler_install_dir>/bin/compilervars.sh intel64

接下來就是用Intel編譯器編譯安裝netcdf庫了:

Building NetCDF* with the Intel® compilers官方文檔

關鍵就是設定幾個編譯選項:

export CC=iccexport CXX=icpcexport CFLAGS=‘-O3 -xHost -ip -no-prec-div -static-intel‘export CXXFLAGS=‘-O3 -xHost -ip -no-prec-div -static-intel‘export F77=ifortexport FC=ifortexport F90=ifortexport FFLAGS=‘-O3 -xHost -ip -no-prec-div -static-intel‘export CPP=‘icc -E‘export CXXCPP=‘icpc -E‘

對於c庫:

$ CPPFLAGS=-I/home/ed/local/include LDFLAGS=-L/home/ed/local/lib ./configure --prefix=/home/ed/local$ make check install

對於Fortran庫:

首先仍然如上設定編譯選項,然後假設你的c庫安裝在路徑${DIR1}:

export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH}

然後和c庫的編譯過程一樣:

CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure --prefix=${DIR1}makemake checkmake install

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.