eclipse油藏数值模拟器的文件读写c/c++算法库libecl在windows下的编译
该库在linux操作系统下使用,但因本人应用场景为windows环境,需要将其编译成dll,这里把填坑过程做个记录:我先是从GitHub上ecl的github地址直接下载zip文件,按着里面的readme.md和WINDOWS.md两个文档,直接对解压后的zip文件进行编译,一直不成功。最后按照两个文件的步骤,编译成功了。成果的github地址:Github库地址,Gitee地址:gitee库地址
能够编译成功的流程:
1、使用Git克隆代码库而不是直接下载zip
$ git clone https://github.com/Equinor/ecl
$ mkdir ecl/build
$ cd ecl/build
$ pip install -r ../requirements.txt
2、make和install命令里的路径写对
WINDOWS.md里给出的命令
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALLPATH% -DBUILD_SHARED_LIBS="ON" -DENABLE_PYTHON="ON" -DCMAKE_BUILD_TYPE="Release" %SOURCEPATH%
cmake --build %BUILDPATH% --config Release --target install
%INSTALLPATH%=我这里设置的为代码库目录下面新建了一个build文件夹
%SOURCEPATH%=代码库目录
%BUILDPATH%=代码库目录
本人环境下的命令:
cmake -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=G:/ythpt/libecl-datapro-py/ecllib/ecl/build -DBUILD_SHARED_LIBS="ON" -DENABLE_PYTHON="ON" -DCMAKE_BUILD_TYPE="Release" G:/ythpt/libecl-datapro-py/ecllib/ecl
cmake --build G:/ythpt/libecl-datapro-py/ecllib/ecl --config Release --target install
3、按WINDOWS.md和readme.md操作
4、WINDOWS.md的内容
WINDOWS.md的内容
Compiling and Installing libecl on Windows
在Windows环境下编译和安装libecl
Prerequisits:前置条件
- Python 2.7 or 3.x https://www.python.org/ or https://anaconda.org/(python,我的是3.10)
- Microsoft Visual Studio https://visualstudio.microsoft.com/downloads/(Visual Studio IDE,主要是用它的MSVC)
- Local copy of libecl(libecl库的本地copy)
Instructions:
- Download or clone the libecl Github repository to your local disk.
Git克隆代码库到本地,Git前升级下Git为最新版 - Python 2.7 or 3.x installation
安装Python- Download a python instalation or a python environment solution such as Anaconda.
- Download and install Microsoft Visual Studio . At a minimum libecl requires the VS Studio packages for cmake, msbuild, c and c++ compilers (CL.exe).
下载安装VS(我的是VS2022),最低要求安装VS的cmake, msbuild, c and c++ compilers (CL.exe),这些组件,安装时勾选C++语言开发,再看看开发工具组件里面勾选,就能满足了 - Open a MSVC command prompt such as x64 Native Tools Command Prompt for VS 2017 from your start menu. In the open prompt, navigate to the libecl source directory you created in step 1. Use the Python package manager pip to install libecl requirements via
pip install -r requirements.txt
. If Python is not accessible from the prompt it may be necessary to add the Python environment location to your system path variablePATH
.
安装libecl的依赖包,我这步是直接在代码库目录下GitBash命令界面输入的,
$ git clone https://github.com/Equinor/ecl
$ mkdir ecl/build
$ cd ecl/build
$ pip install -r ../requirements.txt
-
Execute the build commands with the desired CMAKE parameters from
README.md
. The cmake generator can beNMake Makefiles
,Ninja
or an appropriate version ofMSVC
. For the availble options typecmake -G
in the MSVC command prompt.An example build and install is provided below where %VARIABLE% are user defined directory paths:
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALLPATH% -DBUILD_SHARED_LIBS="ON" -DENABLE_PYTHON="ON" -DCMAKE_BUILD_TYPE="Release" %SOURCEPATH%
cmake --build %BUILDPATH% --config Release --target install
用msvc编译,还是在Git命令窗口直接输入的如下命令,其中%INSTALLPATH%是在代码库目录下新建了的一个build文件夹,最后这个%SOURCEPATH%就是源代码目录
cmake -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=G:/ythpt/libecl-datapro-py/ecllib/ecl/build -DBUILD_SHARED_LIBS="ON" -DENABLE_PYTHON="ON" -DCMAKE_BUILD_TYPE="Release" G:/ythpt/libecl-datapro-py/ecllib/ecl
最后cmake --build %BUILDPATH% --config Release --target install编译和安装,%BUILDPATH%这个我设置成代码库根目录时,能够成功生成
cmake --build G:/ythpt/libecl-datapro-py/ecllib/ecl --config Release --target install
- For libecl to be accessible in Python the
%INSTALLPATH%\lib\pythonX.Y\site-package
and Python subdirectories must be added to thePATH
andPYTHONPATH
variables. Wherepythonx.y
is the current Python version e.g. (python2.7
,python3.6
etc.) . - Open a Python interactive session and run
import ecl
to check that the install and paths are now set.
后续再补充dll的使用
更新:编译成果dll下载链接