使用 Freepascal 编译时如何禁用 RTL

发布于 2024-12-01 10:38:38 字数 833 浏览 1 评论 0原文

我正在为高中生教授使用 pascal 的编程,出于我的好奇心,我发现了一些东西。

我想制作一个简单的pascal源代码批量编译器来编译我学生的源代码文件。但我想限制源代码使用 RTL 单位,比如 math

program test;
uses math;
begin
    writeln(logn(2,2));
end.

logn 是来自 math 单元的函数,因此如果我删除 uses math 行,fpc 编译器在上面编译后将显示错误消息代码。

当我查看 /etc/fpc.cfg 文件时,RTL 单元包含在单元路径中。

# searchpath for units and other system dependent things
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl
#-Fu~/fpc/packages/base/*/units/;~/fpc/fcl/units/;~/fpc/rtl/units/

但在我评论了所有这些行之后,RTL 单元仍然是链接的。作为我的最后手段,我尝试删除 rtl /usr/lib/fpc/2.4.0/units/x86_64-linux/rtl 目录,但奇怪的是源代码仍然可以编译。

有什么建议或者我错过了任何步骤吗?

I'm teaching programming using pascal for high school students and something come out of my curiosity.

I want to make a simple pascal source code batch compiler to compile my students' source code files. But I want to restrict the source code from using RTL units, let's say math.

program test;
uses math;
begin
    writeln(logn(2,2));
end.

The logn is a function from math unit, so naturally if I remove the uses math line, the fpc compiler will show error message after compiling above code.

When I looked into the /etc/fpc.cfg file, the RTL units are included to the unit paths.

# searchpath for units and other system dependent things
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl
#-Fu~/fpc/packages/base/*/units/;~/fpc/fcl/units/;~/fpc/rtl/units/

But after I commented all those lines, the RTL units are still linked. As my last resort I have tried removing the rtl /usr/lib/fpc/2.4.0/units/x86_64-linux/rtl directory, but strangely the source code could still be compiled.

Any suggestion or did I miss any step?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糖 2024-12-08 10:38:38

FPC 包含一些编译的默认单元路径(您可以通过将 -n 传递给编译器来禁用这些路径以及所有配置文件的加载)。尽管如此,编译的路径并不能解释为什么当您删除 /usr/lib/fpc/2.4.0/units/x86_64-linux/rtl 时程序仍然可以编译。要缩小范围,请使用 -va 进行编译并检查输出。以 PPU Loading 开头的行显示编译器获取单元的位置。

FPC contains some compiled-in default units pathes (you can disable those and the loading of all configuration files by passing -n to the compiler). Nevertheless, the compiled-in pathes do not explain why programs still compile when you delete /usr/lib/fpc/2.4.0/units/x86_64-linux/rtl. To narrow this done, compile with -va and examine the output. The lines starting with PPU Loading show you where the compiler gets the units.

逆流 2024-12-08 10:38:38

我刚刚看到这个,但是你看过 /usr/lib/fpc 和 /usr/local/lib/fpc 吗?在我的程序中,有几个版本的 fpc,编译器可能会在编译时找到 rtl 的先前副本。

您也可以尝试在系统中搜索 math.ppu。该文件也可能有多个版本。

最后,如果您要更改 /etc/fpc.cfg,请确保源目录中没有它的其他版本。编译器会先读取本地的fpc.cfg,然后再读取系统的fpc.cfg。

I just saw this, but have you looked at /usr/lib/fpc and /usr/local/lib/fpc? In mine there are a few versions of fpc, and the compiler may be finding a previous copy of the rtl at compile time.

You might also try searching your system for math.ppu. There may be several versions of that file scattered about as well.

Finally, if you're changing /etc/fpc.cfg, make sure that there aren't other versions of it in the source directories. The compiler will read a local fpc.cfg before the system one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文