This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linking Fortran to C++


Americo Barbosa da Cunha Junior wrote:
I've trying to link a Fortran code to a C++ code.

First I create the object files for both languages:

g77  -c  ckinterp.f   math.f   xerror.f  cklib.f  vode.f  conp.f
g++  -c  linear_alg.cpp  teste.cpp

Than I use the g++ to link:

g++ -o jac *.o -lg2c -lm

The GCC returns a message like:

cklib.o: In function `ckcomp_':cklib.f:(.text+0x2b43): multiple definition of `ckcomp_'
ckinterp.o:ckinterp.f:(.text+0xa9b3): first defined here
cklib.o: In function `ifirch_':cklib.f:(.text+0x17d58): multiple definition of `ifirch_'
ckinterp.o:ckinterp.f:(.text+0xa8aa): first defined here
/usr/bin/ld: Warning: size of symbol `ifirch_' changed from 139 in ckinterp.o to 164 in cklib.o
cklib.o: In function `ilasch_':cklib.f:(.text+0x17dfc): multiple definition of `ilasch_'
ckinterp.o:ckinterp.f:(.text+0xa935): first defined here
/usr/bin/ld: Warning: size of symbol `ilasch_' changed from 126 in ckinterp.o to 156 in cklib.o
cklib.o: In function `ipplen_':cklib.f:(.text+0x18654): multiple definition of `ipplen_'
ckinterp.o:ckinterp.f:(.text+0xb1c7): first defined here
cklib.o: In function `ipparr_':cklib.f:(.text+0x1827b): multiple definition of `ipparr_'
ckinterp.o:ckinterp.f:(.text+0xa491): first defined here
/usr/bin/ld: Warning: size of symbol `ipparr_' changed from 1049 in ckinterp.o to 985 in cklib.o
cklib.o: In function `ippari_':cklib.f:(.text+0x17e98): multiple definition of `ippari_'
ckinterp.o:ckinterp.f:(.text+0xa0ae): first defined here
conp.o: In function `MAIN__':conp.f:(.text+0x0): multiple definition of `MAIN__'
ckinterp.o:ckinterp.f:(.text+0x0): first defined here
/usr/bin/ld: Warning: size of symbol `MAIN__' changed from 11317 in ckinterp.o to 3528 in conp.o
xerror.o: In function `xerrwv_':xerror.f:(.text+0xfc0): multiple definition of `xerrwv_'
vode.o:vode.f:(.text+0x7484): first defined here
/usr/bin/ld: Warning: size of symbol `xerrwv_' changed from 457 in vode.o to 593 in xerror.o
/usr/bin/ld: cannot find -lg2c
collect2: ld returned 1 exit status


If you do have multiple versions of the same subroutine (and Fortran MAIN) in your source code, you'll have to figure out which don't belong, and exclude them.
As you have 2 versions of Fortran main program, it's difficult to understand why you would use g++ to link. Why not choose a Fortran, preferably an up to date gfortran, to run the whole show? Something like
gfortran *.f *.cpp -lstdc++ (having selected the proper *.f)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]