There are some things wrong with your example code, which it would be helpful to fix
before attempting to compile it from the command line.
Firstly, you need a project file for fpc
to compile to produce your program. For this,
I created this file in the projects folder and named it hello.lpr
:
program Hello;
uses
hellounit,
main;
begin
HelloWorld;
end.
Then correct Main.Pas as follows:
unit main;
interface
uses helloUnit;
procedure SayHello;
implementation
procedure SayHello;
Begin
helloWorld;
End;
End.
Note that procedure SayHello;
has been added to the interface section and that End;
has been added to the end of the declaration of the procedure. The End.
tells the
compiler that it has reached the end of the source code in the unit.
Next correct helloUnit as follows
unit helloUnit;
interface
procedure helloWorld;
implementation
uses classes;
procedure helloWorld;
begin
writeln('Hello, World');
end; {added}
end.
Now write a batch file CompileHello.Bat
(assuming Windows) in the projects folder
containing
D:\Lazarus2\fpc\3.0.4\bin\i386-win32\fpc -Fufunctions;src hello.lpr
and then run it from a CMD prompt in the projects folder. The -Fu
compiler switch tells fpc
where to find units which are not located in the same folder as the project
file. The paths after -Fu
can be relative to the project folder. If you
have followed the steps above, it should comile successfully.
If you were using Lazarus, the companion IDE to fpc there would be at least two ways of doing what you asked.
With HelloUnit open in the IDE, use View | Add Editor File to Project from the IDE's menu to add HelloUnit to the project. This is probably the best way because it unambiguously identifies HelloUnit for the project.
Add the folder in which HelloUnit.Pas is located to the Project's Source Paths using Project | Options and, in the pop-up, under Compiler Options, add the folder to the Other Unit Files box on the RHS.