Re: Undefined Reference on Compile



On Fri, 9 Jan 2009 06:46:05 -0800 (PST), fj <francois.jacq@xxxxxxx>
wrote in <564377d5-37d2-480e-9a40-0833919d903f@xxxxxxxxxxxxxxxxxxxxxxxxxxx>:

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".
.



Relevant Pages

  • Re: Undefined Reference on Compile
    ... Why are these errors occuring? ... usr/local/include. ...  Note that it seems to have produced a base C library and libraries ... linkers are a lot smarter nowadays than they used to be. ...
    (comp.lang.fortran)
  • Re: Undefined Reference on Compile
    ... Why are these errors occuring? ...  Note that it seems to have produced a base C library and libraries ... Can ifort even be used?! ... Or do i have to use gfortran? ...
    (comp.lang.fortran)
  • Re: compiling with cmake and xlf
    ... indicate fixed-form source and add that flag ... My understanding of xlf is that it does the opposite. ... fortran compilers regarding source file names. ... libraries are continually in conflict with various other C and POSIX ...
    (comp.lang.fortran)
  • Re: C vs. Fortran (half OT questions)
    ... I still need the power of C in system programming though. ... An example of this is the ATLAS BLAS ... fortran is probably the more natural language for things ... This was not always the case for numerical libraries, ...
    (comp.lang.fortran)
  • Re: Matlab Vectorisation Speed - How is it done in c++?
    ... Beating the performance of vectorized Matlab code is very ... Matlab makes calls to optimized C and Fortran libraries ... Use optimization level 3 on numerical code and level 2 on non- ...
    (comp.soft-sys.matlab)