CoolProp as Library in a C++ project

865 views
Skip to first unread message

Renaud Kern

unread,
Jan 18, 2015, 2:40:09 PM1/18/15
to coolpro...@googlegroups.com
Hello,

Thank you for works on CoolProp, it looks awesome.

I wanted to get your advice as how to include CoolProp as library in a C++ project. Do you have some compilation instructions for the C++ sample code ? It doesn't look trivial for me.

Thank you for help.

Best,

Renaud


Jorrit Wronski

unread,
Jan 18, 2015, 6:10:34 PM1/18/15
to Renaud Kern, coolpro...@googlegroups.com

Hi,

you could go for a shared or a static library:

http://www.coolprop.org/coolprop/wrappers/SharedLibrary/index.html#shared-library

http://www.coolprop.org/coolprop/wrappers/StaticLibrary/index.html#static-library

Is that what you were looking for?

Regards,
Jorrit

On 18/01/15 20:40, Renaud Kern wrote:
> Hello,
>
> Thank you for works on CoolProp, it looks awesome.
>
> I wanted to get your advice as how to include CoolProp as library in a
> C++ project. Do you have some compilation instructions for the C++
> sample code
> <http://www.coolprop.org/coolprop/HighLevelAPI.html#c-sample-code>? It
> doesn't look trivial for me.
>
> Thank you for help.
>
> Best,
>
> Renaud
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "coolprop-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to coolprop-user...@googlegroups.com
> <mailto:coolprop-user...@googlegroups.com>.
> To post to this group, send email to coolpro...@googlegroups.com
> <mailto:coolpro...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/coolprop-users.
> For more options, visit https://groups.google.com/d/optout.

--
Jorrit Wronski
DTU Mechanical Engineering

Technical University of Denmark
Department of Mechanical Engineering
Nils Koppels Allé
Building 403 Room 111
2800 Kgs. Lyngby

phone: +45 45 25 41 83
email: jo...@mek.dtu.dk
http://www.mek.dtu.dk/english/Sections/TES

Ian Bell

unread,
Jan 18, 2015, 10:17:05 PM1/18/15
to Jorrit Wronski, Renaud Kern, coolpro...@googlegroups.com
Jorrit's suggestion is a good one, or you could build an entire project using your main file example.cpp:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Make a build folder
mkdir -p build && cd build
# Build the makefile using CMake
cmake .. -DCOOLPROP_MY_MAIN=/path/to/example.cpp
# Make the static library
cmake --build .

On Sun, Jan 18, 2015 at 4:10 PM, Jorrit Wronski <jo...@mek.dtu.dk> wrote:

Hi,

you could go for a shared or a static library:

http://www.coolprop.org/coolprop/wrappers/SharedLibrary/index.html#shared-library

http://www.coolprop.org/coolprop/wrappers/StaticLibrary/index.html#static-library

Is that what you were looking for?

Regards,
Jorrit

On 18/01/15 20:40, Renaud Kern wrote:
Hello,

Thank you for works on CoolProp, it looks awesome.

I wanted to get your advice as how to include CoolProp as library in a
C++ project. Do you have some compilation instructions for the C++
sample code
<http://www.coolprop.org/coolprop/HighLevelAPI.html#c-sample-code>? It

doesn't look trivial for me.

Thank you for help.

Best,

Renaud


--
You received this message because you are subscribed to the Google
Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send

--
Jorrit Wronski
DTU Mechanical Engineering

Technical University of Denmark
Department of Mechanical Engineering
Nils Koppels Allé
Building 403 Room 111
2800 Kgs. Lyngby

phone: +45 45 25 41 83
email: jo...@mek.dtu.dk
http://www.mek.dtu.dk/english/Sections/TES
--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.

Renaud Kern

unread,
Jan 19, 2015, 2:58:01 AM1/19/15
to Ian Bell, Jorrit Wronski, coolpro...@googlegroups.com
Hello,

Thank you for you answers. What was missing to my understanding is the the following statement

cmake .. -DCOOLPROP_MY_MAIN=/path/to/example.cpp

I'm not confident with cmake. Is there an instruction to give the executable file name, like"g++ -o run_example", the default file name is ":/Main".

Best,

Renaud

Ian Bell

unread,
Jan 19, 2015, 3:01:01 AM1/19/15
to Renaud Kern, Jorrit Wronski, coolpro...@googlegroups.com
For the moment the output executable name cannot be changed, but I could add that ability.  Can you please file an issue here: https://github.com/CoolProp/CoolProp/issues


Kyle Campbell

unread,
Sep 28, 2016, 7:04:16 PM9/28/16
to coolprop-users, ian.h...@gmail.com, jo...@mek.dtu.dk
I'm very new to C/C++ too... I just downloaded the static library then tried to run "g++ -ldl -ICoolProp/include example.cpp -ICoolProp -L. -lCoolProp" that returned Error: Cannot find -lCoolProp... ***I entered that on the cmd line from other reading I've done but not quite sure what's going on***

Reading through this seems like I'm in the proper forum area but I am too novice to glean this information correctly. After downloading the static library am I supposed to do a cmake? (btw I am unfamiliar w// cmake)... Why would I have to do anything else once I've downloaded the library? 

I feel like this is probably is simple thing to do getting CoolProp to work but I'm not getting it. Please help with some insight.

REFERENCES:

--
Jorrit Wronski
DTU Mechanical Engineering

Technical University of Denmark
Department of Mechanical Engineering
Nils Koppels Allé
Building 403 Room 111
2800 Kgs. Lyngby

phone: +45 45 25 41 83
email: jo...@mek.dtu.dk
http://www.mek.dtu.dk/english/Sections/TES


--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.

Ian Bell

unread,
Sep 28, 2016, 11:22:36 PM9/28/16
to coolprop-users, Jorrit Wronski
Hi Kyle,

Unfortunately, you cannot just download the static library of CoolProp and drop it into your project, because the compiler version, and compilation flags MUST MATCH EXACTLY between the static library and your code.  It is for that reason that we recommend/require a cmake workflow.  Have you seen this bit of the documentation (from the development version) :


And then you would do (starting in the folder with CMakeLists.txt):

mkdir build
cd build
cmake .. -G "Visual Studio 14 2015 Win64"
cmake --build . --config Release

Here is an example of using this idea in the real world:  https://github.com/usnistgov/phifit/blob/master/CMakeLists.txt

Ask your questions and we'll get you to an answer!

Best,
Ian






Kyle Campbell

unread,
Sep 29, 2016, 12:44:06 PM9/29/16
to coolpro...@googlegroups.com
Thank you this helps a lot! So at the moment my server connection is down so I am attempting this on my mac and the cmake .. -G "Visual Studio 14 2015 Win64" command does not work. My command line responds,  zsh: command not found: cmake... how do I overcome this? (I am in the build directory and .. is the location of CMakeLists.txt)

You received this message because you are subscribed to a topic in the Google Groups "coolprop-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/coolprop-users/NDEfm9AhZVM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to coolprop-users+unsubscribe@googlegroups.com.

To post to this group, send email to coolprop-users@googlegroups.com.

Ian Bell

unread,
Sep 30, 2016, 10:05:05 AM9/30/16
to coolpro...@googlegroups.com
Ah yes, would have been nice if you had mentioned your platform before...

Problem #1: You don't have cmake installed :)  So, install it.  If you are using homebrew (and you should be if you are using OSX), do: brew install cmake

The -G "Visual Studio 14 2015 Win64" is telling cmake to generate a build system for Visual Studio 2015 (64-bit), read the cmake docs to be sure, in your case you probably want

-G Xcode

instead.  You can see the supported generators on your platform by doing "cmake --help" in the terminal

Best,
Ian 

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.

To post to this group, send email to coolprop-users@googlegroups.com.

Kyle Campbell

unread,
Oct 1, 2016, 6:48:20 PM10/1/16
to coolpro...@googlegroups.com
... so I installed cmake and followed your steps and all went well, but then attempting the main.cpp file under "Usage" via http://www.coolprop.org/dev/coolprop/wrappers/StaticLibrary/index.html#cmake-integration I run the compile "g++ -ldl -L. -I../../include main.cpp -lCoolProp" and modify to -I../include to grab the include dir from build. However, I receive this error, 
"ld: library not found for -lCoolProp
clang: error: linker command failed with exit code 1 (use -v to see invocation)"
Why is this occurring? Forgive me in advance for not being very CS savvy. Also, seriously thank you so much for your help, it truly means a lot as I am trying to set this up for the beginning of my grad research.

Ian Bell

unread,
Oct 1, 2016, 8:46:02 PM10/1/16
to coolpro...@googlegroups.com
Hi Kyle, your better bet is to build a CMakeLists.txt file where you define your project and its links to CoolProp, then CMake automatically takes care of all the links.  And it's a crossplatform solution as well.  I've put up a complete and simple example showing how you would do that here: https://github.com/CoolProp/simple_cmake_example 

If you are just starting your research, might I recommend a higher-level language like python?  C/C++ is very powerful, but it is also has a pretty steep learning curve.

Kyle Campbell

unread,
Oct 8, 2016, 6:43:56 PM10/8/16
to coolpro...@googlegroups.com
Hi Ian, my server is back up and running so I can connect again. I have to use C/C++ as this is to add to an existing project. Please continue to be patient with me and help me get to a simple set up of CoolProp.

I have successfully built via cmake, now when I run the simple main.cpp example file in http://www.coolprop.org/coolprop/wrappers/StaticLibrary/ it compiles well but then running the executable I get a permission denied error. I am looking into this in other resources, just wondering if you knew right away the problem. I should add that after compiling, I had to ctl+c to exit. 


Kyle Campbell

unread,
Oct 8, 2016, 8:04:51 PM10/8/16
to coolpro...@googlegroups.com
...disregard that last inquiry, I had to change my permissions to be able to execute. For example, viewed my permissions: "ls -l name.cpp" noticed I did not have execute permission for file so entered: "chmod 744 name.cpp" (https://en.wikipedia.org/wiki/Chmod). Compiled again and ran the executable. Working fine now!

Kyle Campbell

unread,
Oct 9, 2016, 3:57:33 PM10/9/16
to coolpro...@googlegroups.com
Ian,

I am curious regarding http://www.coolprop.org/coolprop/HighLevelAPI.html#c-sample-code that when I switch "Propane" to "CarbonDioxide" and "Ethane" to "Water" I receive an error: Segmentation error core dumped?

Ian Bell

unread,
Oct 11, 2016, 2:56:57 PM10/11/16
to coolpro...@googlegroups.com
Can you please show your code?  Probably that is because there is an exception that is not being trapped.  Did you did a release build or a debug build?



To post to this group, send email to coolprop-users@googlegroups.com.

Kyle Campbell

unread,
Oct 11, 2016, 3:12:40 PM10/11/16
to coolpro...@googlegroups.com
compile: g++ -ldl -L. -I../include propsSI.cpp -o propsSI -lCoolProp
------
#include "CoolProp.h"
#include <iostream>
#include <stdlib.h>

using namespace CoolProp;
int main()
{
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::CO2[0.5]&Water[0.5]") << std::endl;
    return EXIT_SUCCESS;
}
------
Returns Segmentation error (core dumped)

however this works:
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::CO2[0.9993056]&Water[0.0006944]") << std::endl;

this does not:
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::CO2[0.9993055]&Water[0.0006945]") << std::endl;

but then above works when compiling: g++ -g -ldl -L. -I../include propsSI.cpp -o propsSIg -lCoolProp
however any further change in composition returns inf or segmentation error.

I'm pretty sure I did a release build

Ian Bell

unread,
Oct 11, 2016, 3:21:26 PM10/11/16
to coolpro...@googlegroups.com
Yes, CO2+Water is a nasty mixture.  Flash calculations with it are very challenging.  It has an open phase envelope, making robust phase equilibria calculations problematic.  You should expect errors with CO2+Water, and should wrap calculations in try....catch blocks.

Kyle Campbell

unread,
Oct 11, 2016, 8:05:45 PM10/11/16
to coolpro...@googlegroups.com
I got it to work well for higher temperatures and pressures, although I am having difficulty developing a working iteration for an interval of different fractions (CO2 10%-90%) without altering the library.
Reply all
Reply to author
Forward
0 new messages