问题
My Fortran code needs to call C++ function named SolveBIE_(), and this function is written in one file, e.g. test.c. SolveBIE_() needs to call some other C++ functions written in other files, e.g. part01.c, part02.c. I also claim those functions in part01.h and part02.h. Then I use
$ gcc -c part01.c
$ gcc -c part02.c
$ ar cr kf.a part01.o part02.o part01.h part02.h
to get my kf.a. I link the kf.a as a object file in my fortran compiling. I am using intel fortran ifort and a makefile. I got an error in my make. Here is the makefile script.
FC = ifort
IFC_OPT = -O3 -ipo -unroll
FFLAGS = -extend_source -mp1 -xW -w95 -cm $(IFC_OPT) -cm
LINKFLAGS = -LFFTPACK -ldfftpack
CC = cc
HS_OBJECTS = xx.o kf.a ...\ objectfile
VEL = vel_new_massflux.o matvec.o
MAIN = xx.o new_restart.o
hsflux_objs = $(MAIN) $(VEL) $(HS_OBJECTS)
hsflux: $(hsflux_objs)
$(FC) -o hsflux $(FFLAGS) $(hsflux_objs) $(LINKFLAGS)
hsfluxd_objs = driver_massflux_debug.o $(VEL) $(HS_OBJECTS)
hsflux_debug: $(hsfluxd_objs)
$(FC) -o hsflux_debug $(FFLAGS) $(hsfluxd_objs) $(LINKFLAGS)
$(FC) $(FFLAGS) -o testfft2 testfft2.o FAST.o xfft.o $(LINKFLAGS)
.f.o:
$(FC) -c $(FFLAGS) $*.f
.c.o:
$(CC) -c $*.c
clean:
/bin/rm -f *.o *~
VISCFING_FILES=Makefile *.f *.F *.c *.h FFTPACK Scripts PARAMS
The error is
ipo: warning #11021: unresolved SolverBIE_
Referenced in /tmp/ipo_ifortUqyTSb.o
/tmp/ipo_ifortUqyTSb.o: In function 'MAIN_':
ipo_out.f:(.text+0x5442): undefined reference to 'SolveBIE_'
The detail of the C++ code and Fortran code is here, another question I asked, it seems that problem is solved. But I need to complete the compiling to make sure. C++ code and fortran code
回答1:
Going back to your linked code, the Fortran has
integer (C_INT) function SolveBIE_(x, y, aa, m) BIND(C, NAME='SolveBIE_')
Whereas the C has
int solveBIE_(double *ini_bdry_x, double *ini_bdry_y, double *ini_bdry_um, int *fM)
The Fortran part is thus looking for a symbol called SolveBIE_
while the C part is providing a symbol called solveBIE_
. The difference in case of every character matters!
来源:https://stackoverflow.com/questions/48696645/undefined-reference-to-solvebie-when-binding-c-and-fortran