如何编译Sun Pascal';s模到它在自由Pascal中的等价物?

如何编译Sun Pascal';s模到它在自由Pascal中的等价物?,pascal,porting,freepascal,Pascal,Porting,Freepascal,我有一个用Sun Pascal编写的程序,它由一个程序单元和几个模块单元组成,现在我想把它转换成免费的Pascal。 因此,我开始在Sun Pascal 3.0.2用户指南(第52页)中测试该示例: 方案股: program program_unit (output); procedure say_hello; extern; begin say_hello end. 模块单元: module module_unit; procedure say_hello; begin writeln ('

我有一个用Sun Pascal编写的程序,它由一个程序单元和几个模块单元组成,现在我想把它转换成免费的Pascal。 因此,我开始在Sun Pascal 3.0.2用户指南(第52页)中测试该示例:

方案股:

program program_unit (output);
procedure say_hello; extern;
begin
say_hello
end.
模块单元:

module module_unit;
procedure say_hello;
begin
writeln ('Hello, world.')
end;
我对源文件做了一些修改:在program_unit中,我添加了一行“{$link program_unit.p}”,然后将修饰符“extern”改为“external”

然后我试着用fpc编译它:

fpc程序单元

但它失败了:

Free Pascal Compiler version 2.6.2-8 [2014/01/22] for x86_64
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling program_unit.p
Linking program_unit
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
module_unit.p: file not recognized: File format not recognized
program_unit.p(6,1) Error: Error while linking
program_unit.p(6,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)

要使编译工作顺利进行,我还需要做哪些修改?

正如David Heffernan在他的评论中所写,您应该学习该语言,但好了,现在开始吧

模块的FreePascal等价物是一个单位。主程序不是一个单元,它是程序(主项目文件)。因此,让您的程序看起来像:

program myprogram; // (output) is not required.

uses
  module_unit;

begin
  say_hello
end.
您的模块单元如下所示:

unit module_unit;

{$mode objfpc}{$H+}

interface

procedure say_hello;

implementation

procedure say_hello;
begin
  Writeln('Hello, world.')
end;

end.
现在只需将
module\u unit
添加到
myprogram
项目并构建。然后可以从控制台/shell运行程序。导航(使用
cd
)到编译它的目录,然后在Linux或OS X上输入
/myprogram
,或在Windows中输入
myprogram
myprogram.exe


FWIW,我建议您使用lazaruside,而不是命令行。它使添加单元、编辑程序和其他许多事情变得更加容易。

在尝试移植代码之前,您需要学习两种语言。这是您的下一步。$link用于对象文件而不是源文件,并且显示的模块不是任何标准语法(既不是TP也不是ISO/Extended Pascal),因为缺少任何形式的声明部分(接口或实现)。我查看了sun手册,它的语法似乎是正确的,但其他任何东西都不支持它,因为它违反了基本的Pascal使用前声明原则。