分页: 1 / 1

如何编译 fortran

发表于 : 2009-04-05 14:05
heroyee
新手,刚接触linux,还不甚了解编译方面的事情
希望各位多多帮助

Re: 如何编译 fortran

发表于 : 2009-04-05 16:41
greco
fortran?

强啊,用这个语言

搞数学的 :em04

自己看他的README,上面写的很清楚

Re: 如何编译 fortran

发表于 : 2009-04-05 19:01
syrano
sudo aptitude install gfortran #安装
gfortran filename.f95 -o filename

Re: 如何编译 fortran

发表于 : 2009-04-05 19:06
syrano
建议楼主用gun debug 调试.
gfortran -g -Wall filename.f95 -o filename #编译出可调试的文件
gdb filename #调试 filename

gdb基本用法如下(详见http://wiki.ubuntu.org.cn/index.php?tit ... iant=zh-cn

代码: 全选

$ gdb tst   <---------- 启动GDB
GNU gdb 6.7.1-debian
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) l 1 <-------------------- l命令相当于list,从第一行开始列出源码。
1       #include <stdio.h>
2
3       int func(int n)
4       {
5               int sum=0,i;
6               for(i=1; i<=n; i++)
7               {
8                       sum+=i;
9               }
10              return sum;
(gdb)    <-------------------- 直接回车表示,重复上一次命令
11      }
12
13
14      int main()
15      {
16              int i;
17              long result = 0;
18              for(i=1; i<=100; i++)
19              {
20			result += i;
(gdb) break 16    <-------------------- 设置断点,在源程序第16行处。
Breakpoint 1 at 0x80483b2: file tst.c, line 16.
(gdb) break func   <-------------------- 设置断点,在函数func()入口处。
Breakpoint 2 at 0x804837a: file tst.c, line 5.
(gdb) info break   <-------------------- 查看断点信息。
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x080483b2 in main at tst.c:16
2   breakpoint     keep y   0x0804837a in func at tst.c:5
(gdb) r    <--------------------- 运行程序,run命令简写
Starting program: /home/dbzhang/tst 

Breakpoint 1, main () at tst.c:17
17		long result = 0;
(gdb) n     <--------------------- 单条语句执行,next命令简写。
18		for(i=1; i<=100; i++)
(gdb) n
20			result += i;
(gdb) n
18		for(i=1; i<=100; i++)
(gdb) n
20			result += i;
(gdb) c    <--------------------- 继续运行程序,continue命令简写。
Continuing.
result[1-100] = 5050    <----------程序输出。

Breakpoint 2, func (n=250) at tst.c:5
5		int sum=0,i;
(gdb) n
6		for(i=1; i<=n; i++)
(gdb) p i   <--------------------- 打印变量i的值,print命令简写。
$1 = -1074568236
(gdb) n
8			sum+=i;
(gdb) n
6		for(i=1; i<=n; i++)
(gdb) p sum
$2 = 1
(gdb) n
8			sum+=i;
(gdb) p i
$3 = 2
(gdb) n
6		for(i=1; i<=n; i++)
(gdb) p sum
$4 = 3
(gdb) bt   <--------------------- 查看函数堆栈。
#0  func (n=250) at tst.c:6
#1  0x080483f1 in main () at tst.c:24
(gdb) finish   <--------------------- 退出函数。
Run till exit from #0  func (n=250) at tst.c:6
0x080483f1 in main () at tst.c:24
24		printf("result[1-250] = %d \n", func(250) );
Value returned is $5 = 31375
(gdb) c   <--------------------- 继续运行。
Continuing.
result[1-250] = 31375    <----------程序输出。

Program exited normally.   <--------程序退出,调试结束。
(gdb) q   <--------------------- 退出gdb。