我有一个用Sun Pascal编写的程序,它由一个程序单元和几个模块单元组成,我现在想将它转换为Free Pascal。 于是我开始通过测试孙帕斯卡尔3.0.2用户指南的例子(第52页,https://docs.oracle.com/cd/E19957-01/801-5054/801-5054.pdf):如何将Sun Pascal的模块编译为Free Pascal的等效模块?
程序单元:
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 program_unit.p
但它失败:
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)
什么更多的修改我应该做的工作,编制?
尝试移植代码之前,您需要学习两种语言。这是你的下一步。 –
$链接是用于目标文件而非源文件的 –
并且由于缺少任何形式的声明部分(接口或实现),所示模块不是任何标准语法(既不是TP也不是ISO/Extended Pascal)。我查了太阳手册,它似乎是它的语法,但这不会被其他任何东西支持,因为它违反了基本的Pascal在使用原则之前声明。 –