Perfect Developer basic tutorial 4 | This page last modified 2011-10-30 (JAC) |
From the Project menu select Create file. Select the Perfect main entry point option and then click OK. The filename Main.pd will be filled in for you.
Next, in the editor, change the import directive to read:
Change the postcondition of the schema main to read:
Build and verify the project (which now has two files).
How you create an executable program now depends on whether you are using C++ or Java and on what development environment you are using.
If you are using Java, we suggest you read our Knowledge Base article Creating a Java application using Perfect Developer and JDK. The critical factors are:
Version 1.6 of Java is needed.
You need to choose a package name (e.g. books) and set the package name in the Perfect Developer project. For Perfect Developer version 2.0 you do this by adding the option -gk=books in the Additional options field on the Miscellaneous tab of the project settings. For later versions, you should instead enter the package name on the Code Generation tab.
On the Code Generation tab, set the Target language to Java. The Target Compiler setting does not matter because Java is highly standardized.
Most Java development systems are very fussy about what directories the source files are placed in. You should create subdirectories src and classes within your project directory. We also suggest you create a subdirectory called output to hold the generated archive file. Assuming your chosen package name is books then create a books subdirectory within src and another within classes. Java source files for package books need to be placed in src/books, so on the Code Generation tab of the project settings, change Output directory to Specified Directory and browse to src/books.
Make sure that the Java CLASSPATH includes not only your Classes directory but also the PerfectRuntime.jar file. The easiest way to do this is to copy PerfectRuntime.jar into your output subdirectory and then include output/PerfectRuntime.jar in your CLASSPATH. If you wish to use a debug version of the runtime library, use PerfectRuntimeD instead of PerfectRuntime.
You need to create a Java source file containing a main class. We suggest that you adapt the file Entry.java that we provide in the HelloWorld example project.
The HelloWorld project that we provide in the Examples subdirectory of the Perfect Developer installation includes a script file postbuildjava.bat (Windows) or postbuildjava (Linux) that automates some of the above.
If you are using C++ under Windows and your compiler is Microsoft Visual C++ 6.0, see Creating a Perfect console application using Visual C++.
If you are using C++ with the GNU compiler gcc, do the following:
Ensure you are using gcc version 3.01 or later.
On the Code Generation tab of the Perfect Developer project settings, change Target Compiler to gcc.
When compiling the generated files with gcc, use optimisation level 2 or lower unless compiling with gcc version 3.31.
Include the Runtime/Include/Cpp directory of Perfect Developer in the gcc include-files path.
Link with the library Runtime/Lib/Cpp/PerfectRuntime.lib (or PerfectRuntimeD.lib for a debug build).
If you want to automate the build process, you can configure a Post-build step command file on the Build tab of the project settings to automatically invoke a program such as make.
When you have successfully built your C++ or Java project, running it from a command prompt should produce the output:
Now you can experiment by making changes to the Main.pd file. What happens if you break a precondition (e.g. by creating a book with no authors)? How does the result depend on the Runtime checks setting on the Code generation tab?
Next: Schemas
Save My Place | Glossary | Language Reference Manual |
Copyright © 1997-2012 Escher Technologies Limited. All rights reserved. Information is subject to change without notice. |