Boost logo

Boost-Build :

From: Jorge Suit Perez Ronda (josp_at_[hidden])
Date: 2006-05-18 04:48:37


Hello, bellow I describe my situation with an example: Hello World in
fortran.

On Thu, 2006-05-18 at 10:40 +0400, Vladimir Prus wrote:
> I believe that gfortran.jam just uses gcc to compile fortran files.
> While this
> is not suitable for you, and why do you want to explicitly use "g77"
> command?
>
> Sorry for ignorance, but having no fortran experience I'd need to
> understand
> the requirements first.
>
> - Volodya

========= hello.f (also attached) ==========
      PROGRAM EXAMPLE
      PRINT *,'Hello world'
      END
============================================

======== Jamroot (1 try) ===================
using gfortran ;
exe hello : hello.f ;
============================================

============ output this ===================
warning: no toolsets are configured.
...
error: unable to construct ./hello
error: no generators were found for type 'EXE'
...
============================================

======== Jamroot (2 try) ===================
using gfortran ;
using gcc ;
exe hello : hello.f ;
============================================

============ output this ===================
gfortran.compile.fortran bin/gcc/debug/hello.o
gcc.link bin/gcc/debug/hello
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'
bin/gcc/debug/hello.o: In function `MAIN__':
/tmp/hello.f:2: undefined reference to `_gfortran_filename'
/tmp/hello.f:2: undefined reference to `_gfortran_line'
...
...failed gcc.link bin/gcc/debug/hello...
============================================

======== Jamroot (3 try) ===================
using gfortran ;
using gcc ;
lib gfortran : : <name>gfortran ;

exe hello : hello.f gfortran ;
============================================

============ output this ===================
gcc.link bin/gcc/debug/hello
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'

    "g++" -o "bin/gcc/debug/hello" -Wl,--start-group
"bin/gcc/debug/hello.o" -lgfortran -Wl,--end-group -g

============================================

after that I try the same command failed to link and change "g++" for
"gfortran" just typing at the command line:

"gfortran" -o "bin/gcc/debug/hello" -Wl,--start-group
"bin/gcc/debug/hello.o" -lgfortran -Wl,--end-group -g

and it was ok, as a matter of fact if I use (note that -lgfortran is not
specified)

"gfortran" -o "bin/gcc/debug/hello" -Wl,--start-group
"bin/gcc/debug/hello.o" -Wl,--end-group -g

the it will link ok.

Until here the situation is: if the main entry program (main) is in a
fortran source then it could not be "declared" as an "exe" target
because g++ does not know how to do it, it is expecting a main and
gfortran generate a MAIN. So may be a solution could be, as Volodya
suggest to define an fortran_exe rule, but may be a better solution is
around.

Then the other thing is related to compile with g77 (Fortran 77) and not
with gfortran (Fortran 95). As taken from the gfortran's manual pages:

"Gfortran is not yet a fully conformant Fortran 95 compiler. It can
generate code for most constructs and expressions, but work remains to
be done. In particular, there are known deficiencies with ENTRY,
NAMELIST, and sophisticated use of MODULES, POINTERS and DERIVED TYPES.
For those whose Fortran codes conform to either the Fortran 77 standard
or the GNU Fortran 77 language, we recommend to use g77 from GCC 3.4. We
recommend that distributors continue to provide packages of g77-3.4
until we announce that gfortran fully replaces g77. The gfortran
developers welcome any feedback on user experience with gfortran at
<fortran_at_[hidden]>."

What I did was to make a copy of gfortran.jam into g77.jam (attached)
and modified in order to use g77. The I repeat the 3 steps described
with gfortran and similar results where obtained.

Sorry for the, may be boring, long description,

best regards,

Jorge.


# Copyright (C) 2004 Toon Knapen
#
# Use, modification and distribution is subject to the Boost Software
# License Version 1.0. (See accompanying file LICENSE_1_0.txt or
# http://www.boost.org/LICENSE_1_0.txt)

import toolset : flags ;
import feature ;
import fortran ;

rule init ( version ? : command * : options * )
{
}

# Declare flags and action for compilation
flags g77 OPTIONS <fflags> ;

flags g77 OPTIONS <optimization>off : -O0 ;
flags g77 OPTIONS <optimization>speed : -O3 ;
flags g77 OPTIONS <optimization>space : -Os ;

flags g77 OPTIONS <debug-symbols>on : -g ;
flags g77 OPTIONS <profiling>on : -pg ;

flags g77 OPTIONS <link>shared/<main-target-type>LIB : -fPIC ;

flags g77 DEFINES <define> ;
flags g77 INCLUDES <include> ;

rule compile.fortran
{
}

actions compile.fortran
{
  g77 -Wall $(OPTIONS) -D$(DEFINES) -I$(INCLUDES) -c -o "$(<)" "$(>)"
}

generators.register-fortran-compiler g77.compile.fortran : FORTRAN : OBJ ;



Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk