VS2010 VC ++ LNK 2019 error with CoolProp 5.0.0

I am an amateur VC ++ developer.

I want to use CoolProp ( http://www.coolprop.org/ ) in my VC ++ training project as a static library in a win 32 app using VS2010 Ultimate running on x64 laptop.

So I downloaded,

1.CoolProp.lib from http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.2/static_library/ 2.CoolProp.h from http://sourceforge.net/projects/coolprop/files/CoolProp/ 5.0.0 / shared_library /

and placed as in the system folder.

Then I created a sample win32 console application in VS2010 as an empty sln. Added CoolProp.h as additional Include directories in properties -> C / C ++ -> General (also copied all dependent header files) Added CoolProp.lib as additional dependencies in properties -> Linker-> Input-> Additional Dependencies

Then I copied this program from http://www.coolprop.org/coolprop/HighLevelAPI.html#high-level-api

#include "CoolProp.h"
#include <iostream>
using namespace CoolProp;
int main()
{
// First type (slowest, due to most string processing, exposed in DLL)
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]") << std::endl; //      Default backend is HEOS
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]") << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane[0.5]&Ethane[0.5]") << std::endl;

std::vector<double> z(2,0.5);
// Second type (C++ only, a bit faster)
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane&Ethane", z) << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane&Ethane", z) << std::endl;
std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane&Ethane", z) << std::endl;

return EXIT_SUCCESS;
}

      

and tried to build.

Build (but compiled perfectly) failed due to

main.obj: error LNK2019: unresolved external symbol "double __cdecl PropsSI (char, char, double, char, double, char *)" (? Props @@ YANDDNDNPAD @Z) referenced by function _main

Can someone please help me in solving this? I have already read below post from stackoverflow but could not solve please help

+3


source to share


2 answers


It works for me (VS 2010) like this:
-add "CoolPropLib.h" to your project by right clicking on the header files folder in Solution Explorer -> Add -> Existing Item -> select "CoolPropLib.h".
-open the "CoolPropLib.h" file and comment line 22 as follows (// # include "PlatformDetermination.h").
- add these two lines (23, 24):

 #define CONVENTION __stdcall
 #define EXTERNC

      


-use a library that is built with __stcall that is not built with __cdecel:
http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/Windows/32bit__stdcall_calling_convention/CoolProp.lib/download
- you need dll (for __stdcall):
http://sourceforge.net/projects/coolprop/files/CoolProp/5.0.0/shared_library/Windows/32bit__stdcall_calling_convention/CoolProp.dll/download

-create a folder called "lib" in your project folder in Windows Explorer (not VS) and place "CoolProp.lib" in it.

-in Properties-> Linker-> General-> Additional Libraries Directories, add $ (ProjectDir) \ lib
- the code I'm testing:



#include "stdafx.h"
#include <iostream>
#include <vector>
#include "CoolPropLib.h"
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{

    // First type (slowest, due to most string processing, exposed in DLL)
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"Propane[0.5]&Ethane[0.5]") << std::endl; //      Default backend is HEOS
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"HEOS::Propane[0.5]&Ethane[0.5]") << std::endl;
    std::cout << PropsSI("Dmolar","T",298,"P",1e5,"REFPROP::Propane[0.5]&Ethane[0.5]") << std::endl;

    return 0;
}

      

- if you have problems, I can upload the project to you.


EDIT 1:

  • I mean "CoolPropLib.h" not "CoolProp.h", I'm fixing that; In your question, you named it "CoolProp.h".
  • As you mentioned in your comment; you can change the calling convention as _stdcall in Properties-> c / C ++ -> Advanced.
+3


source


I am one of the main developers of CoolProp. Thanks @houssam for your answer. The problem with migrating to a DLL (shared library) is that you lose access to a lot of useful low-level functions, whereas if you link to a static library you have access to all the low-level code

The best plan is to build the static library yourself, as it requires the compiler used to build the static library to be EXACTLY the same as the compiler used to compile your project. To do this, you can follow the following guidelines: http://www.coolprop.dreamhosters.com:8010/sphinx/coolprop/wrappers/StaticLibrary/index.html#static-library , basically you need to do

# 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 build && cd build
# Build the makefile using CMake
cmake .. -DCOOLPROP_STATIC_LIBRARY=ON -G "Visual Studio 10 2010"
# Make the static library
cmake --build .

      



Then you need to link the static library as @houssam described. No other changes are required for your code.

In the future, the coolprop-users@googlegroups.com mailing list or https://github.com/CoolProp/CoolProp/issues are good places to ask questions.

+3


source







All Articles