Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29249 Discussions

linking external libraries when compiling

tmbrown
Beginner
1,923 Views
Hello,

I'm trying out an evaluation copy of the Intel compiler with various Fortran packages I use in my research. All of these packages compile w/o errors with g77 on my Mac Intel (Leopard 10.5.2) machine, but so far I've only had success with one package using the Intel compiler. That one successful package runs 10x faster when compiled with the Intel compiler (compared to g77), so I am keen to see if I can get my other packages compiled with the Intel compiler, too.

With one of the problematic packages, the problem seems to lie with linking of external libraries. These are 32-bit libraries, so I am using the 32-bit ifort instead of the 64-bit ifort I was able to use in the package I compiled successfully. All of my object code is created successfully, but the compiler is failing for calls to the external libraries. I am probably just doing something stupid here.

My Makefile looks like this:

F77 = /opt/intel/fc/10.1.014/bin/ifort
FFLAGS = -c -O2
LFLAGS = -O2
HOSTLIBS = -lm
IMFORT = /usr/stsci/iraf/irafbin/bin.macintel/libimfort.a /usr/stsci/iraf/irafbin/bin.macintel/libsys.a /usr/stsci/iraf/irafbin/bin.macintel/libvops.a /usr/stsci/iraf/iraf/unix/bin.macintel/libos.a
FITLIB = /Users/tbrown/code/daophot/cfitsio/libcfitsio.a

# RULES:
.SUFFIXES: .o .f
.f.o:
$(F77) $(FFLAGS) $<

daophot: daophot.o pckpsf.o find.o fotometry.o
psf.o peak.o nstar.o fudge.o addstar.o substar.o
group.o sort.o lnxsubs.o bothsubs.o iosubs.o mathsubs.o
$(F77) $(LFLAGS) -o daophot daophot.o pckpsf.o find.o fotometry.o
psf.o peak.o nstar.o fudge.o addstar.o substar.o
group.o sort.o lnxsubs.o bothsubs.o
iosubs.o mathsubs.o
$(IMFORT) $(HOSTLIBS) $(FITLIB)


When I try to "make daophot" I get a pile of successfully-created object files, but then I get the following error messages:
Undefined symbols:
"_s_copy", referenced from:
_imemsg_ in libimfort.a(imemsg.o)
...
_f77pak_ in libvops.a(f77pak.o)
...
"_pow_di", referenced from:
_ctod_ in libsys.a(ctod.o)
...
"_pow_ri", referenced from:
_ctod_ in libsys.a(ctod.o)
...
"_i_len", referenced from:
_imemsg_ in libimfort.a(imemsg.o)
...
ld: symbol(s) not found

These libraries (libimfort.a, libsys.a, etc.) are part of a software package called IRAF that provide IRAF functionality within Fortran programs. I am guessing I am just doing something idiotic when linking them, although as I said this all works fine if I use g77.

Thanks,
Tom

0 Kudos
7 Replies
Steven_L_Intel1
Employee
1,923 Views
Your external libraries were compiled with g77. As such, they cannot be linked in with ifort code. You must get a new version of those libraries built with ifort. All Fortran sources must be recompiled with ifort - you cannot mix Fortran code compiled with different compilers.

This is pretty much the case with any Fortran compiler you will find.
0 Kudos
tmbrown
Beginner
1,923 Views
Thanks for your response. That's unfortunately not an option, it seems.

When I asked about recompiling these libraries with ifort, I was told the following:

What compiler to use on a certain platform is hardcoded in the iraf internals. I know it's possible but not trivial to change some compilers, actually the only case I can think of is changing Sun's cc to gcc on Solaris. The problem is that the iraf libraries you list are written in spp and then converted to fortran on the fly and for this iraf uses a specific fortran version. Well, in short, I am not aware of a way to compile iraf with the intel fortran compiler.


0 Kudos
Steven_L_Intel1
Employee
1,923 Views
Sorry, there's no solution then other than to stick with g77.
0 Kudos
tmbrown
Beginner
1,923 Views
Thanks for your reply.

I just got another reply from one of the IRAF package support people. It solved my problem, so I'm posting it here for reference.

The IRAF libraries were built using F2C/GCC as the compilers, to use another compiler you still need to link in the $iraf/unix/bin.macintel/libf2c.a and the system libgcc.a (just add a '-lgcc' to the library list). This should resolve the undefined refs but I can't guarantee compatibiliy with the Intel compilers.

0 Kudos
Steven_L_Intel1
Employee
1,923 Views
f2c!!!! Augh!

Anyway, I'm glad you found a solution.
0 Kudos
tmbrown
Beginner
1,923 Views
So now I'm down to my third and final Fortran package. The first package was working by a simple substituion of g77 with ifort, while the second required the 2 additional links that came up in my last question.

This third package should be easier than that previous one, but I can't get it going. It's another case of mixing compilers, but I believe this is one that people do all the time: calling C routines from Fortran. I can compile all the object files (C and Fortran) just fine, but when I try to make the executable, I get a pile of Undefined Symbols errors again. In this case, I've added the -lgcc flag to allow the linking of files compiled with C, but that did not help.

Is there some Intel-specified flag to allow this? Like my previous problem, it compiles with g77 just fine, but not the 32-bit ifort.

Thanks,
Tom

0 Kudos
tmbrown
Beginner
1,923 Views
Never mind! Playing with the Makefile, I was able to get it to work (with the -lgcc flag).


0 Kudos
Reply