Re: Undefined Reference on Compile



On Jan 9, 9:47 am, "Dr Ivan D. Reid" <Ivan.R...@xxxxxxxxxxxx> wrote:
On Fri, 9 Jan 2009 06:46:05 -0800 (PST), fj <francois.j...@xxxxxxx>
 wrote in <564377d5-37d2-480e-9a40-0833919d9...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>:



On Jan 7, 2:25 pm, "Dr Ivan D. Reid" <Ivan.R...@xxxxxxxxxxxx> wrote:
On Wed, 7 Jan 2009 08:35:51 -0800 (PST), deadpickle <deadpic....@xxxxxxxxx>
 wrote in <b58793ee-5f30-4c5f-9c97-d27d5509d...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>:
I'm trying to compile a simple fortran program that uses the grib_api
library.
ifort -o /home/deadpickle/Desktop/gribapi1 gribapi1.o -L/usr/local/
lib/ -lgrib_api
Why are these errors occuring? Did I do something wrong when I went to
make the grib_Api library?
        Just to be clear, does /usr/local/lib/libgrib_api.a (or .so) exist?
yes it does.
For compiling correctly, you also need to find the file grib_api.mod
which is surely located either in /usr/local/lib or more probably in /
usr/local/include. This file is loaded in the same way as include
files :

gfortran -o yourcode.exe gribapi1.f90 -I/mnt/share/narr -I/usr/local/
include -L/usr/local/lib -lgrib_api

        Right, this two-stage process just worked for me (as far as
compiling...), after including USE GRIB_API in the main programme.

[ivan:~] > gfortran -c -Igrib_api_dir/include test.f90
[ivan:~] > gfortran test.o  -Lgrib_api_dir/lib -lgrib_api_f90 -lgrib_api

where I'd specified ~/grib_api_dir as the base directory in my ./configure
command.  Note that it seems to have produced a base C library and libraries
for g77 and gfortran (both installed on this particular machine), so for
Fortran you need the appropriate extra library to be linked as well,
and I daresay it needs to be specified before the base library unless
linkers are a lot smarter nowadays than they used to be.

[ivan:~] > ls -l grib_api_dir/lib
-rw-r--r--  1 ivan ivan 5189150 Jan  8 17:30 libgrib_api.a
-rw-r--r--  1 ivan ivan  154218 Jan  8 17:30 libgrib_api_f77.a
-rw-r--r--  1 ivan ivan  171912 Jan  8 17:30 libgrib_api_f90.a
[ivan:~] > ls -l grib_api_dir/include/
-rw-r--r--  1 ivan ivan  3229 Jan  8 17:30 grib_api_f77.h
-rw-r--r--  1 ivan ivan 39693 Jan  8 17:30 grib_api.h
-rw-r--r--  1 ivan ivan 43217 Jan  8 17:30 grib_api.mod

[ivan:~] > uname -a
Linux s94n126.brunel.ac.uk 2.6.9-78.0.8.EL.cernsmp #1 SMP \
Thu Nov 27 15:19:42 CET 2008 i686 i686 i386 GNU/Linux

--
Ivan Reid, School of Engineering & Design, _____________  CMS Collaboration,
Brunel University.    Ivan.Reid@[brunel.ac.uk|cern.ch]    Room 40-1-B12, CERN
GSX600F, RG250WD         "You Porsche. Me pass!"   DoD #484     JKLO#003, 005
WP7# 3000   LC Unit #2368 (tinlc)   UKMC#00009   BOTAFOT#16    UKRMMA#7 (Hon)
        KotPT -- "for stupidity above and beyond the call of duty".

I ran configure using FC=ifort and F77=ifort and it made it through
with no errors.
I have tried to compile using the same method you all have stated
above but with ifort:
ifort -c -I/usr/local/include/ gribapi1.f90
ifort -o /home/deadpickle/Desktop/gribapi1 gribapi1.o -L/usr/local/lib
-lgrib_api_f90 -lgrib_api

And I get this:
.