Библиотека сайта rus-linux.net
Linux Compilers and AssemblersSEP 19, 2003 By Christopher Paul, Rafeeq Rehman. Article is provided courtesy of Prentice Hall. |
3.10 Compiling Pascal ProgramsPascal programs can be converted to C language programs and then compiled in the usual way. The (* Program to demonstrate Pascal compilation *) program Hello ; begin writeln ('Hello world') end. The following command will create a file [rr@conformix 4]$ p2c hello.pas Hello Translation completed. [rr@conformix 4]$ The output /* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "hello.pas" */ /* Program to demonstrate Pascal compilation */ #include <p2c/p2c.h> main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); printf("Hello world\n"); exit(EXIT_SUCCESS); } /* End. */ You may need some libraries with Many Pascal compilers are also available in the open source world. These compilers can be used to generate executable code from Pascal source directly without any help from GCC. 3.10.1 Using Free Pascal (fpc)The Free Pascal Project has created a 32-bit Pascal compiler which is available for Linux, among other operating systems. You can download it from http://www.freepascal.org. This software is licensed under GPL like other open source projects. At the time of writing this book version 1.0.4 is available for download. After download, you can install the compiler as follows on a RedHat system: [root@conformix rr]# rpm --install fpc-1.0.4.i386.rpm Write permission in /etc. Found libgcc.a in /usr/lib/gcc-lib/i386-redhat-linux/2.96 Writing sample configuration file to /etc/ppc386.cfg [root@conformix rr]# The best thing about this compiler is that you don't need to convert source code files to C language and then compile these.
The fpc compiler creates binary executable files. The following command creates an executable file [rr@conformix 4]$ fpc hello.pas Free Pascal Compiler version 1.0.4 [2000/12/18] for i386 Copyright (c) 1993-2000 by Florian Klaempfl Target OS: Linux for i386 Compiling hello.pas Assembling hello Linking hello 6 Lines compiled, 0.1 sec [rr@conformix 4]$ The output 3.10.2 Using GNU PascalA GNU Pascal compiler is available from http://agnes.dida.physik.uni-essen.de/~gnu-pascal/ for download and can be installed on many platforms like © 2003 Pearson Education, Inc. InformIT Division. All rights reserved. 800 East 96th Street Indianapolis, Indiana 46240 |