1
votes

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?

2

2 Answers

3
votes

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.

0
votes

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.