I have a FORTRAN code which needs a C routine to calculate a measure. The C routine includes .c and .h files and in the documentation it is written:
If you want to embed the hypervolume function into your own C/C++ code, the main function for computing the hypervolume (
fpli_hv
) is self-contained in the filehv.c
. A simple way to add it to your own code is to include Makefile.lib into your Makefile and link againstfpli_hv.a
. The exported function is:"
double fpli_hv(double *front, int d, int n, double *ref);
The makefile.lib is also as follows:
VARIANT ?= 4
HV_SRCS = hv.c
HV_HDRS = hv.h
HV_OBJS = $(HV_SRCS:.c=.o)
HV_LIB = fpli_hv.a
$(HV_LIB): $(HV_OBJS)
@$(RM) $@
$(QUIET_AR)$(AR) rcs $@ $^
## Augment CFLAGS for hv.[co] objects
hv.o: CPPFLAGS += -D VARIANT=$(VARIANT)
## Dependencies:
$(HV_OBJS): $(HV_HDRS)
How can I embed this C routine in FORTRAN makefiles? Could you please help me, perhaps by providing an illustrative example. I searched for this issue and found a number of examples, but they all showed simple examples which did not require manipulating makefiles.
Including
Makefile.lib
into anotherMakefile
should add one new target calledfpli_hv.a
(also will define theHV_LIB
macro). You should add it as dependency to one of the targets in the makefile used to build the Fortran code. For example:Original
Makefile
, used to build the Fortran codeModification should be as simple as:
Or if you are not going to change and recompile the C code often then you could simply build the library, then add something like this to your Fortran
Makefile
:Probably the original hypervolume
Makefile
already includesMakefile.lib
so you should be able to build the library by something likemake fpli_hv.a
in the directory where the hypervolume source code is.