CoolProp / REFPROP-headers

This is a tiny repository that contains header files for the REFPROP fluid property library. The header files should work with both C++ and C, but they have only been tested with C++ so far.
MIT License
18 stars 9 forks source link

undefined reference to dll #26

Open MitchelDaniel opened 10 months ago

MitchelDaniel commented 10 months ago

Hi, having a small issue using the REFPROP_lib.h header.

When compiling, I am getting errors saying that there are undefined references, to "WMOLdll" for example.

At the top of my C code, I am using

#define REFPROP_PROTOTYPES
#include "REFPROP_lib.h"
#undef REFPROP_PROTOTYPES

I am calling the functions like this: XMASSdll(xmol, xkg, &molwt) And getting this as my compilation output:

func.c: In function 'myfunc':
func.o: In function `myfunc':
func.c:(.text+0xfc): undefined reference to `WMOLdll'
func.c:(.text+0x12a): undefined reference to `CRITPdll'
func.c:(.text+0x1c8): undefined reference to `TPFLSHdll'
func.c:(.text+0x2c1): undefined reference to `TSFLSHdll'
func.c:(.text+0x594): undefined reference to `TSFL1dll'
func.c:(.text+0x60e): undefined reference to `THERMdll'
func.o: In function `myfunc2':
func.c:(.text+0x9c6): undefined reference to `XMASSdll'
func.c:(.text+0xa2f): undefined reference to `TPRHOdll'
func.c:(.text+0xa72): undefined reference to `CVCPdll'
func.c:(.text+0xb7f): undefined reference to `THERM2dll'
func.c:(.text+0xc7d): undefined reference to `TRNPRPdll'
collect2: error: ld returned 1 exit status

Am I missing something?

Also, in the repo, there is no C example, only C++, would you consider adding that?

Thanks

ibell commented 10 months ago

Sounds like a linking problem. How did you compilation go?

MitchelDaniel commented 10 months ago

Compilation failed. output is in first post. I will edit to make clearer

ibell commented 10 months ago

My question was what commands you ran at command line

MitchelDaniel commented 10 months ago

I have a makefile, the compilation command (see LIBS for my linking with refprop):

#NOTE ... a tab character is REQUIRED at the beginning of every recipe line
#   Action ... : prerequisites ...
#   <tab>recipe
TARGET = flowcalc

# define the compiler to be used
CC = gcc
FC = gfortran
# debug
DEBUG = -g
# warnings
WARN = -Wall

CFLAGS = $(WARN) $(DEBUG) `pkg-config --cflags gtk+-3.0`
FFLAGS = $(WARN) $(DEBUG) `pkg-config --cflags gtk+-3.0`

GTKLIB = `pkg-config --cflags --libs gtk+-3.0`

# define any libraries to link into executable
LIBS = -lm -lgfortran /usr/local/lib/librefprop.so \
    /usr/local/lib/libmodbus.so -lpthread -fPIC $(GTKLIB)

# this rule keeps make from doing something with files 
# called "clean" or "all" or "default"
.PHONY: clean all default fRefProp.o fSetNew.o

#all: default
# change the list of all C source files into a list of object files
COBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
# change the list of all fortran source files into a list of object files
FOBJECTS = $(patsubst %.for, %.o, $(wildcard *.for))
# create a list of all header files
HEADERS = $(wildcard *.h)

# the .o files depend on all .c and .h files
# generate the .o files using CC (gcc) and CFLAGS (-Wall -g)
# -c ... generate the object files
# -o $@  ...  put the output of the compilation in the file named left of the :
# the $<  ... the first item in the dependencies list
%.o: %.c $(HEADERS)
    $(CC) $(CFLAGS) -c $< -o $@

%.o: %.for
    $(FC) $(FFLAGS) -c $< -o $@ 

.PRECIOUS: $(TARGET) $(COBJECTS) $(FOBJECTS)

#final compile of all .o files
$(TARGET): $(COBJECTS) $(FOBJECTS)
    $(CC) $(COBJECTS) $(FOBJECTS) $(WARN) $(LIBS) -o $@

clean:
    -rm -f *.o
ianhbell commented 10 months ago

Please first try with the provided CMake build file

MitchelDaniel commented 10 months ago

Do I need to edit the CMakeLists.txt for my own project? I am new to using cmake.

Thanks

ianhbell commented 10 months ago

Well, first thing is to build with CMake following the instructions, make sure you can get the examples to build and run, then next step is to add into your own code. CMake is much superior to Makefiles since they are cross-platform

MitchelDaniel commented 10 months ago

I think I got confused with what the purpose of REFPROP-headers is. I have a REFPROP license, using librefprop.so library (will be upgrading to the cmake build system soon). Since this repo is associated with CoolProp, should I not even be using this repo? Because I'm able to call a number of Refprop functions without using #include REFPROP_lib.h", but using #include "refprop_lib.h" instead. If so, then I will close this issue.

ianhbell commented 10 months ago

Well, librefprop.so is the historical way of building REFPROP on non-windows platforms. That has been since superceded by https://github.com/usnistgov/REFPROP-cmake

This library is used for calling REFPROP from C/C++, what was used in CoolProp initially. But it has no dependency on any other CoolProp things, by design. You can use static linking or dynamic linking with this header.

MitchelDaniel commented 10 months ago

I understand. However, if I use #include "refprop_lib.h" (I believe this came with librefprop.so), instead of #include "REFPROP_lib" (the one that came with REFPROP-headers). I'm still able to make calls to REFPROP, for example TPRHOdll(<arguments>) so, I may not even need to use this?

What is the difference between these two header files?

ianhbell commented 10 months ago

There are some additional functions (like the functions from REFPROP 10) in the REFPROP-headers one that are strongly advised to be used in general, unless speed is absolutely essential.