EPANET2.0 编译成x64的dll

epanet的项目里自带一个x86的dll,如果不介意的话直接用这个也行。。

一、下载epanet

八仙过海各凭本事。。。github也有,epa官网也有,同济也有。。

二、编译

从git下载的epanet有四个文件夹
EPANET2.0 编译成x64的dll
第一个是gui,无视,主要是第三个,编译SRC_engines即可。
epa给的文档里是这么说的
“All the files except main.c are needed to build the DLL version of the solver.
The file main.c needs to be incudled for building a command-line executable.
Epanet2.def should be inculded as a module definition file
for building the DLL that can be used in EPANET user inferface (epanet2w.exe). ”
主要就是第一段,编译除了main以外的所有函数,第三段提到的.def用不到。
所以打开vs,建立c++ dll项目,在头文件中选择添加现有项,添加所有.h,在源文件中同样,添加所有.c。
生成项目。

三、问题解决

此时一般会有函数过时,预编译头缺失和dllimport无法添加这三个错误。
EPANET2.0 编译成x64的dll
函数过时在文件刚开始添加
#define _CRT_SECURE_NO_WARNINGS
即可

预编译头在项目属性里把预编译头改为不使用即可。

dllimport在文件刚开始添加
#ifdef _EXPORTING
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
并且在 VS 的“预编译”选项里定义_EXPORTING

重新生成项目,成功,尝试调用
EPANET2.0 编译成x64的dll
调用成功

over

##PS:编译完的上传****了