Missing format function definition causes dll compilation failure.

22 views
Skip to first unread message

John French

unread,
Jun 16, 2025, 6:11:17 PMJun 16
to coolprop-users
System: Windows 11 Pro for Workstations  --  Version: 24H2 (OS Build 26100.4349)
Using: VS Community 2022 C++

In previous posting was mentioned some error handling issues that were commented out to allow compilation of the dll.

I wish to be more precise here and hopefully be helpful to those with the skill set to fix these issues ...

Compilation errors >>

...\CoolPropTools.h(99,40): error C3861: 'format': identifier not found
...\CoolPropTools.h(107,40): error C3861: 'format': identifier not found
...\CoolPropTools.h(127,40): error C3861: 'format': identifier not found
...\CoolPropTools.h(135,40): error C3861: 'format': identifier not found

A single error repeated in 4 places.

My commenting out hack sabotages robustness and a skillful solution will benefit everyone using static library with C++.

    void add_string_vector(const std::string& s1, const std::vector<std::string>& d) {
        string_vectors.insert(std::pair<std::string, std::vector<std::string>>(s1, d));
    }
    std::string get_string(const std::string& s) const {
        strings_map::const_iterator i = strings.find(s);
        if (i != strings.end()) {
            return i->second;
      } else {
          throw CoolProp::ValueError(format("%s could not be matched in get_string", s.c_str()));
      }
    };

commenting hack >>
...
     } else {
          ;  //throw CoolProp::ValueError(format("%s could not be matched in get_string", s.c_str()));
      }

The solution of above is an excellent teaching opportunity!

Ian Bell

unread,
Jun 16, 2025, 6:18:51 PMJun 16
to coolpro...@googlegroups.com
Seems like you didn't do a recursive clone, what commands did you run to re-build the shared library?

--
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 view this discussion visit https://groups.google.com/d/msgid/coolprop-users/fe353c44-ebb1-4846-b226-5c47aa79d943n%40googlegroups.com.

John French

unread,
Jun 16, 2025, 10:16:49 PMJun 16
to coolprop-users
I will rebuild with the recursive switch set and compare results. I am new to using both github and CMake and some examples have/don't have recursive set. In my many attempts ... I was all over the map. Will be awesome if that's the solution!

This might also affect usage of HAPropsSI()? 
Even though code has >> #include "HumidAirProp.h" ...  had to use this call >>  HumidAir::HAPropsSI()
Personal learning curve has steepened of recent thanks to the desire to incorporate CoolProp into a long term project ... not painless but absolutely worth it ... new worlds to explore!!

Thanks for the tip! 

John French

unread,
Jun 17, 2025, 11:58:14 AMJun 17
to coolprop-users
Probably I have done some rookie mistake that is causing me much grief. Hopefully there is sufficient detail to reveal such. If not ... I will try my best to provide additional information.
Possibly something is missing in this massive project's repository?

Rebuilt the C++ lib from scratch in PowerShell 7 (x64) >>
1)  git clone --recursive https://github.com/CoolProp/CoolProp C:\Users\17134\Documents\CoolProp_Recursive
2)  cd C:\Users\17134\Documents\CoolProp_Recursive
3)  mkdir -p build
4)  cd build
5)  cmake .. -G "Visual Studio 17 2022" -A x64 -DCOOLPROP_STATIC_LIBRARY=ON
6)  cmake --build . --config Release

There were some minor build warnings that are listed last. 

Compiling an example CoolProp main.cpp and making these settings changes >>

Additional Include Directories >>  C:\Users\17134\Documents\CoolProp_Recursive\include;C:\Users\17134\Documents\CoolProp_Recursive\externals\fmtlib\include\fmt;%(AdditionalIncludeDirectories)
Note: The 2nd directory above was an attempt to resolve the problem.

Additional Library Directories >>  C:\Users\17134\Documents\CoolProp_Recursive\build\Release;%(AdditionalLibraryDirectories)

Additional Dependencies >>  CoolProp.lib;%(AdditionalDependencies) 

I have tried both of the following >>
a) C++ Language Standard >>  Default (ISO C++14 Standard)
b) C++ Language Standard >>  ISO C++20 Standard (/std:c++20)

... Produces this error >>
C:\Users\17134\Documents\CoolProp_Recursive\include\CPstrings.h(15,14): error C1083: Cannot open include file: 'fmt/format.h': No such file or directory

Below are affected files name/line numbers before and after hacked/commenting necessary to allow compilation.

File Name >>  CPstrings.h

15   #    include "fmt/format.h"  // For addition of the string formatting functions and macros from fmtlib
16   #    include "fmt/printf.h"  // For sprintf

   @@@@@
   Note: Line #15 comment references fmtlib and this folder >> C:\Users\17134\Documents\CoolProp_Recursive\externals\fmtlib 
   is populated with other folders and header files found here >> C:\Users\17134\Documents\CoolProp_Recursive\externals\fmtlib\include\fmt
   I have zero experience with fmtlib; however, I did stumble around trying to figure out if a missing include header file would resolve these issues ....  absolutely no success.
   Recursive git missing a component?
   @@@@@

84   inline std::string format(const char* format, fmt::ArgList args) {
85        return fmt::sprintf(format, args);
86    }
87   FMT_VARIADIC(std::string, format, const char*)

132  if ((pEnd - &(cs[0])) != static_cast<int>(s.size())) {
133      // Found a character that is not able to be converted to number
134      throw CoolProp::ValueError(format("Unable to convert this string to a number:%s", cs));
135  } else {
136      return val;
137  }

Hacked/Commenting To Allow Compilation >>

15   // #    include "fmt/format.h"  // For addition of the string formatting functions and macros from fmtlib
16   // #    include "fmt/printf.h"  // For sprintf

84   // inline std::string format(const char* format, fmt::ArgList args) {
85   //      return fmt::sprintf(format, args);
86   //  }
87   // FMT_VARIADIC(std::string, format, const char*)

134  ;// throw CoolProp::ValueError(format("Unable to convert this string to a number:%s", cs));

----------------------------------------------------------------------

File Name >>  CPnumerics.h

424   throw CoolProp::ValueError(
425       format("Too small numbers: %f cannot be tested with an accepted error of %f for a machine precision of %f. ", max, D, DBL_EPSILON));

Hacked/Commenting To Allow Compilation >>

424   ;// throw CoolProp::ValueError(
425    //    format("Too small numbers: %f cannot be tested with an accepted error of %f for a machine precision of %f. ", max, D, DBL_EPSILON));

----------------------------------------------------------------------

File Name >>    CoolPropTools.h

98        } else {
99          throw CoolProp::ValueError(format("%s could not be matched in get_string", s.c_str()));
100       }

Hacked/Commenting To Allow Compilation >>

98        } else {
99         ;// throw CoolProp::ValueError(format("%s could not be matched in get_string", s.c_str()));
100       }

Note: The above error and hacked/commenting is repeated at lines: 107, 127, 135

As mentioned above ... here is a list of minor build warnings >>

C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(3,13): warning C4005: '_CRT_SECURE_NO_WARNINGS': macro redefinition [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
      C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(3,13):
      '_CRT_SECURE_NO_WARNINGS' previously declared on the command line

C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(233,39): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(281,36): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(282,39): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(408,22): warning C4267: 'return': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(576,29): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(611,29): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(914,35): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]
C:\Users\17134\Documents\CoolProp_Recursive\src\CoolPropLib.cpp(919,39): warning C4267: '=': conversion from 'size_t' to 'long', possible loss of data [C:\Users\17134\Documents\CoolProp_Recursive\build\CoolProp.vcxproj]

  Generating Code...
  miniz.c
  CoolProp.vcxproj -> C:\Users\17134\Documents\CoolProp_Recursive\build\Release\CoolProp.lib
  Building Custom Rule C:/Users/17134/Documents/CoolProp_Recursive/CMakeLists.txt

Ian Bell

unread,
Jun 17, 2025, 6:31:36 PMJun 17
to coolpro...@googlegroups.com
Two things:
0) Use CMake to build your exe as well. Example here: https://github.com/CoolProp/simple_cmake_example . That will fix missing include paths, as they are passed to your exe built target via exported target include paths
1) You should not need to do any funny business with the fmtlib; it should build out of the box if the include paths are correct.

Please show your example code.

Reply all
Reply to author
Forward
0 new messages