I do know how to compile a basic Pascal program:<div><br></div><div><div>$ cat hello.p</div><div>program Hello;</div><div>begin</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>writeln('Hello World!')</div>

<div>end.</div></div><div><br></div><div>$ fpc hello.p</div><div><div><br></div><div>$ ./hello</div><div>Hello World!</div></div><div><div><br></div><div>The problem I'm trying to solve is that it appears Pascal can't build executables from units, that is units by themselves.</div>

<div><br></div><div><div>$ cat scriptedmain.p</div><div>unit ScriptedMain;</div><div><span class="Apple-tab-span" style="white-space:pre">      </span>interface</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">   </span>function MeaningOfLife () : integer;</div>

<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">     </span>implementation</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">      </span>function MeaningOfLife () : integer;</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>begin</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>MeaningOfLife := 42</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>end;</div>

<div>initialization</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>write('Main: The meaning of life is: ');</div><div><span class="Apple-tab-span" style="white-space:pre">     </span>writeln(MeaningOfLife())</div>

<div>end.</div></div><div><br></div><div>$ fpc scriptedmain.p</div><div><br></div><div><div>$ ./scriptedmain</div><div>-bash: ./scriptedmain: No such file or directory</div></div><div><br></div><div>I can USE the code just fine in a second file, test.p, and compile and run a test executable. But I'd like to be able to turn my units into self-sufficient executables (and later add command line options).</div>

<div><br></div>Cheers,<div><br></div><div>Andrew Pennebaker</div><div><a href="http://www.yellosoft.us" target="_blank">www.yellosoft.us</a></div>
<br><div class="gmail_quote">On Thu, Oct 13, 2011 at 4:42 PM, Jonas Maebe <span dir="ltr"><<a href="mailto:jonas.maebe@elis.ugent.be">jonas.maebe@elis.ugent.be</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br>
On 13 Oct 2011, at 22:32, Andrew Pennebaker wrote:<br>
<br>
> On Thu, Oct 13, 2011 at 3:40 PM, Jonas Maebe <<a href="mailto:jonas.maebe@elis.ugent.be">jonas.maebe@elis.ugent.be</a>>wrote:<br>
><br>
>> On 13 Oct 2011, at 21:37, Andrew Pennebaker wrote:<br>
>><br>
>>> Is it possible to have a begin/end declaration in a unit a la C's main<br>
>>> function? I would like my units to double as libraries and executables.<br>
>><br>
>> Yes: <a href="http://www.freepascal.org/docs-html/ref/refse72.html" target="_blank">http://www.freepascal.org/docs-html/ref/refse72.html</a><br>
</div><div class="im">> Hmm. I tried rewriting begin/end as initialization/end, but scriptedmain.p<br>
> still won't compile to an executable. fpc just creates a .PPU file.<br>
<br>
<br>
</div>As the above-mentioned page says (emphasis mine):<br>
<br>
***<br>
A unit contains a set of declarations, procedures and functions that can be *used by a program* or another unit.<br>
...<br>
The initialization parts of the units are executed in the order that the compiler loaded the units *when compiling a program*. They are *executed before the first statement of the program* is executed.<br>
***<br>
<br>
Here's how you write a program: <a href="http://www.freepascal.org/docs-html/ref/refse71.html" target="_blank">http://www.freepascal.org/docs-html/ref/refse71.html</a><br>
<br>
You may also want to go through the entire tutorial I linked to earlier: <a href="http://www.learn-programming.za.net/programming_pascal_learn01.html" target="_blank">http://www.learn-programming.za.net/programming_pascal_learn01.html</a><br>


<font color="#888888"><br>
<br>
Jonas_______________________________________________<br>
</font><div><div></div><div class="h5">fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br></div>