1

I tried out the Fortran Wapper in CoolProp Sources

The example fortran code given in the wrapper uses the function PropsSI in CoolProp.

double precision T,Q,D,h,s,P
      character(LEN=32) Ref,Output, Name1, Name2
      double precision outVal,Prop1,Prop2

      integer inte

      T = 400
      Q = 1;

      Output = "D"//CHAR(0)
      Name1  = "Q"//CHAR(0)
      Prop1  = Q
      Name2  = "T"//CHAR(0)
      Prop2  = T
      Ref    = "IF97::Water"//CHAR(0)
      outval = 9999999  


      call PropsSi(Output, Name1, Prop1, Name2, Prop2, Ref, outVal)

I followed these steps to call the above function in Modelica:

  1. Built a static Coolprop library: In the root directory of the CoolProp(also tried out in my own package repo) I built a static library with the code:
mkdir build && cd build
mkdir gccstatic && cd gccstatic
cmake ../..  -DCOOLPROP_STATIC_LIBRARY=ON -DCOOLPROP_EXTERNC_LIBRARY=ON -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build .

The library generated in the code was moved then to the modelica package repo

  1. Linked fortran file to Coolprop shared libary libCoolProp.a. Used multiple methods but the logic was the same:
f77 main.f -L. -lCoolProp

  1. Used external keyword in modelica to call the function
function propssi
  extends Modelica.Icons.Function;
  input Real T;
  input Real Q;
  output Real D;
  protected 
  String out = "D";
  String n1 = "Q";
  String n2 = "T";
  String ref= "IF97::Water";

  external "FORTRAN 77" D = PropsSI(out, n1, Q, n2, T, ref) annotation(Library = {"testfunction"});
end propssi;

After doing this in multiple variations, i am getting a compilation error from modelica which i cant figure out.

/usr/bin/ld: /usr/local/lib/libCoolProp.a(CoolPropLib.cpp.o): undefined reference to symbol '_ZTVN10__cxxabiv121__vmi_class_type_infoE@@CXXABI_1.3' /usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [UseFortran.makefile:37: omc_main_target] Error 1 Compilation process failed. Exited with code 2.

Can anyone suggest alternate methods to access the coolprop library functions or to properly call the existing fortran example code

aahliffe
  • 11
  • 2
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it in Fortran?](https://stackoverflow.com/questions/66855252/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – veryreverie Apr 28 '22 at 07:44
  • Is `_ZTVN10...` defined in `my_lib`, or is it a dependency of `my_lib` defined elsewhere? You can use [this method](https://stackoverflow.com/a/1250597/8559300) to find out. – veryreverie Apr 28 '22 at 07:48
  • Also, you say you linked to `libCoolProp.a`, but your flag is `-lmy_lib`. I'm confused. – veryreverie Apr 28 '22 at 07:52
  • 1
    The `_ZTVN10__cxxabiv121__vmi_class_type_infoE...`thing looks like something coming from a C++ class, not from Fortran. Are you mixing `g++` and `clang`? Are you doing it in the way that is supported? You will need to show the exact command that generates the error message. Consider using different tags to attract the right experts. This missing symbol really does not come from Fortran but from C++. See https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Vladimir F Героям слава Apr 28 '22 at 08:04
  • @VladimirFГероямслава thanks for the reply :D its my first question here so please excuse the tags. The coolprop source that i mentioned is a pre-compiled c++ library. The function i am trying to call using the fortran code is within that. I dont exactly know the g++ and clang function in the mix as it is used by the modelica compiler – aahliffe Apr 29 '22 at 14:49
  • Is there any particular detail in how you call the modelica linking? I have no idea how that is done. See https://github.com/illuhad/hipSYCL/issues/125 You can try forcing `clang++` or adding `libstdc++` to the linked libraries. – Vladimir F Героям слава Apr 29 '22 at 14:54
  • @veryreverie i just mentioned the code -lmy_lib as syntax, I realise how that could be misleading and have edited it. – aahliffe Apr 29 '22 at 15:09
  • OpenModelica will use clang and link with the libraries listed. I would either build a shared library (linked against C++), use the setCompiler API to change the compiler to clang++ (requires users to set this in their settings or mos-scripts), or add stdc++ to Library annotation (but that would not be portable since the library might not be named stdc++). – sjoelund.se Apr 29 '22 at 16:56

0 Answers0