Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use Coolprop in visual studio community 2022 #2367

Open
liuwei-kyushu opened this issue Apr 9, 2024 · 2 comments
Open

how to use Coolprop in visual studio community 2022 #2367

liuwei-kyushu opened this issue Apr 9, 2024 · 2 comments

Comments

@liuwei-kyushu
Copy link

Excuse me.
I am not good at programing.
Who can teach me step by step how to use Coolprop in visual studio community 2022 (visual C++ 2022)?

@ibell
Copy link
Contributor

ibell commented Apr 9, 2024

You'll need cmake, once you have that going, you need to make a folder called bld (or whatever you want) in the CoolProp source, and make a file called my main.cpp, with the contents perhaps like these ones: http://www.coolprop.org/coolprop/wrappers/StaticLibrary/index.html#usage, open a terminal there, and then do something like:

cmake .. -DCOOLPROP_MY_MAIN=mymain.cpp

and then open the generated project file in your VS instance.

@birdol
Copy link

birdol commented Apr 29, 2024

This is a help document written in Chinese。
这是一份中文的帮助文档。
作者/Author @birdol
Url:https://www.birdol.com/cainiaobiancheng/24.html

主要方法来自于这里:

http://www.coolprop.org/coolprop/wrappers/Csharp/index.html#user-compiled-binaries

补充了一些踩坑过程。

〇、依赖
来源:http://www.coolprop.org/coolprop/wrappers/index.html#wrapper-common-prereqs

编译过程需要依赖这些东西:

git (to interface with the CoolProp repository at https://github.com/CoolProp/CoolProp)

python (to generate the header files and convert them to binary file)

CMake (platform-independent software to generate makefiles)

C++ compiler

7-zip

 

都需要加入到环境变量中,即:在命令行直接执行时,可以调用的到。比如:

On Windows, download the newest binary installer for CMake from CMake downloads. Run the installer. Check that at the command prompt you can do something like:

C:\Users\XXXX>cmake -version
cmake version 2.8.12.2


For git, your best best is the installer from http://msysgit.github.io/. Check that at the command prompt you can do something like:

C:\Users\XXXX>git --version
git version 1.9.4.msysgit.0


For 7-zip, download the installer from http://www.7-zip.org/ . Check that at the command prompt you can do something like:

C:\Users\XXXX>7z

7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]

一、下载
命令 git clone https://github.com/CoolProp/CoolProp --recursive   

这个命令因为科学网的原因,可能会下载不完整,推荐使用github desktop进行下载。

二、修改错误
修改:
coolprop\dev\generate_headers.py

gitrev_to_file 函数改为以下内容。

def gitrev_to_file(root_dir):
 """
 If a git repo, use git to update the gitrevision. If not a git repo, read
 the gitrevision from the gitrevision.txt file. Otherwise, fail.
 """
 hashes['gitrevision'] = "myprop20230425"
修改:
coolprop\src\CoolProp.cpp

65行找不到引用,注释掉 gitrevision.h的引用

963行提示未定义标识符gitrevision,改为version

三、编译
32位
 
mkdir build86 && cd build86
 
cmake .. -DCOOLPROP_CSHARP_MODULE=ON -DCOOLPROP_NO_EXAMPLES=ON -DCOOLPROP_SWIG_OPTIONS="-namespace MyProp" -G "Visual Studio 15 2017"
 
cmake --build .
64位
mkdir build64 && cd build64
 
cmake .. -DCOOLPROP_CSHARP_MODULE=ON -DCOOLPROP_NO_EXAMPLES=ON -DCOOLPROP_SWIG_OPTIONS="-namespace MyProp" -G "Visual Studio 15 2017 Win64"
 
cmake --build .
编译完成后,会在build文件夹里生成 platform-independent.7z,这个压缩包里的内容是C#调用Coolprop需要的中间件。

注意上述的指令中,使用了namespace,设置为MyProp,对应生成的中间件也会跟着变化,需要配套使用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants