我有一個用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在使用原則之前聲明。 –