Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to dll #26

Open
MitchelDaniel opened this issue Nov 8, 2023 · 11 comments
Open

undefined reference to dll #26

MitchelDaniel opened this issue Nov 8, 2023 · 11 comments

Comments

@MitchelDaniel
Copy link

MitchelDaniel commented Nov 8, 2023

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

@MitchelDaniel MitchelDaniel changed the title SIZE_T_TYPE must be defined undefined reference to dll Nov 8, 2023
@ibell
Copy link
Contributor

ibell commented Nov 8, 2023

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

@MitchelDaniel
Copy link
Author

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

@ibell
Copy link
Contributor

ibell commented Nov 11, 2023 via email

@MitchelDaniel
Copy link
Author

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
Copy link
Contributor

Please first try with the provided CMake build file

@MitchelDaniel
Copy link
Author

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

Thanks

@ianhbell
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants