我喜歡我的圖書館作爲可執行文件加倍。期望的行爲是:帕斯卡單位可以編譯爲可執行文件嗎?
$ ./scriptedmain
Main: The meaning of life is: 42
$ ./test
Test: The meaning of life is: 42
如何我:
- 獲取
scriptedmain.p
編譯成二進制scriptedmain
? - 阻止
test.p
運行scriptedmain.p
的begin
/end
節中的代碼?
scriptedmain.p:
unit ScriptedMain;
interface
function MeaningOfLife() : integer;
implementation
function MeaningOfLife() : integer;
begin
MeaningOfLife := 42
end;
begin
write('Main: The meaning of life is: ');
writeln(MeaningOfLife())
end.
當我編譯fpc scriptedmain.p
scriptedmain.p,沒有可執行文件被創建,因爲帕斯卡爾檢測到它是一個單元。但我希望它是一個除了庫之外的可執行文件。
$ ./scriptedmain
-bash: ./scriptedmain: No such file or directory
test.p:
program Test;
uses
ScriptedMain;
begin
write('Test: The meaning of life is: ');
writeln(MeaningOfLife())
end.
當我編譯test.p與fpc test.p
,生成的可執行文件組合這兩個begin
/end
聲明(不是所需的行爲)。
$ ./test
Main: The meaning of life is: 42
Test: The meaning of life is: 42
那麼,使用一個空的主程序? –