Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-12

How to compile program from command line on Linux?

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have written a command line utility program on Linux using Lazarus as the IDE. This was done a while ago on an Ubuntu Desktop 20.04 machine, which I normally access using VNC when doing Lazarus work there.

Now since a few months the TigerVNC server on that machinbe won't start anymore so I cannot reach Lazarus.
But I can log on just fine using PuTTY from Windows and do whatever on the command line.

So what I want to do is to modify the source, which I can do via SSH. But then I want to build a new version of the program without access to Lazarus there.

Can this be done and in that case how?
Last build of the application was using fpc ver 3.2.2 and probably Lazarus 2.2.4

I have never compiler a FreePascal program from the command line before....

TIA

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 17 lines
I have written a command line utility program on Linux using Lazarus as the IDE. This was done a while ago on an Ubuntu Desktop 20.04 machine, which I normally access using VNC when doing Lazarus work there. Now since a few months the TigerVNC server on that machinbe won't start anymore so I cannot reach Lazarus. But I can log on just fine using PuTTY from Windows and do whatever on the command line. So what I want to do is to modify the source, which I can do via SSH. But then I want to build a new version of the program without access to Lazarus there. Can this be done and in that case how? Last build of the application was using fpc ver 3.2.2 and probably Lazarus 2.2.4 I have never compiler a FreePascal program from the command line before....

If you have a .lpi file (lazarus project file) then you can do simply a

lazbuild yourproject.lpi

lazbuild is a command-line tool that comes with lazarus, it can be used to compile a project file with the same settings as would be used if you were compiling in the IDE.

Michael.

Reply by email

Bart
to Bo Berglund: I have written a command line utility program on Linux using Lazarus as the IDE. This was…
Can this be done and in that case how?

Yes, of course it can be done.
Lazarus IDE just calls the compiler with the correct parameters ;-)

If you happen to have a compiled version of lazbuild on the computer in question it's easy.
Just a lazbuild myproject (not sure if an extension must be given) should do it. AFAIK you can also specify the build-mode (if your project has buildmodes) on the commandline.

If you don't have lazbuild, then you have to figure out what to supply mainly for the unit-paths that are needed (-Fu parameter) to built the project.
Normally the IDE can tell you that, but you cannot access the IDE. So you need the path to all units (where *.o and *.ppu) reside (for e.g. LCL, LazUtils etc.

If you have access to any Lazarus on any PC you can get an idea of how that looks for a similar project.
Goto Colpiler Options -> Show compiler options.
This will show all parameters that the IDE gives to the compiler, including all unitpaths.

Bart

Reply by email

Bo Berglund
to Michael Van Canneyt: If you have a .lpi file (lazarus project file) then you can do simply a lazbuild…
Michael Van Canneyt wrote 31 lines
On Mon, 16 Dec 2024, Bo Berglund via fpc-pascal wrote: > I have written a command line utility program on Linux using Lazarus as the IDE. > This was done a while ago on an Ubuntu Desktop 20.04 machine, which I normally > access using VNC when doing Lazarus work there. > > Now since a few months the TigerVNC server on that machinbe won't start anymore > so I cannot reach Lazarus. > But I can log on just fine using PuTTY from Windows and do whatever on the > command line. > > So what I want to do is to modify the source, which I can do via SSH. > But then I want to build a new version of the program without access to Lazarus > there. > > Can this be done and in that case how? > Last build of the application was using fpc ver 3.2.2 and probably Lazarus 2.2.4 > > I have never compiler a FreePascal program from the command line before.... If you have a .lpi file (lazarus project file) then you can do simply a lazbuild yourproject.lpi lazbuild is a command-line tool that comes with lazarus, it can be used to compile a project file with the same settings as would be used if you were compiling in the IDE. Michael.

I have now entered the bugfix and tried to use lazbuild, but the command is not found...

$ lazbuild videosplitcmb.lpi
lazbuild: command not found

Seems like it is not on path..

My project sources are in ~/projects/VideoSplitCombine

And Lazarus and lazbuild itself is in ~/dev/lazarus/2.2.4/ But not on path...

Should I copy lazbuild to ~/bin where fpc also is located? Or invoke it like this:

~/dev/lazarus/2.2.4/lazbuild videosplitcmb.lpi

TIA

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote 52 lines
On Mon, 16 Dec 2024 14:19:56 +0100 (CET), Michael Van Canneyt via fpc-pascal wrote: > > >On Mon, 16 Dec 2024, Bo Berglund via fpc-pascal wrote: > >> I have written a command line utility program on Linux using Lazarus as the IDE. >> This was done a while ago on an Ubuntu Desktop 20.04 machine, which I normally >> access using VNC when doing Lazarus work there. >> >> Now since a few months the TigerVNC server on that machinbe won't start anymore >> so I cannot reach Lazarus. >> But I can log on just fine using PuTTY from Windows and do whatever on the >> command line. >> >> So what I want to do is to modify the source, which I can do via SSH. >> But then I want to build a new version of the program without access to Lazarus >> there. >> >> Can this be done and in that case how? >> Last build of the application was using fpc ver 3.2.2 and probably Lazarus 2.2.4 >> >> I have never compiler a FreePascal program from the command line before.... > >If you have a .lpi file (lazarus project file) then you can do simply a > >lazbuild yourproject.lpi > >lazbuild is a command-line tool that comes with lazarus, it can be used to >compile a project file with the same settings as would be used if you were >compiling in the IDE. > >Michael. I have now entered the bugfix and tried to use lazbuild, but the command is not found... $ lazbuild videosplitcmb.lpi lazbuild: command not found Seems like it is not on path.. My project sources are in ~/projects/VideoSplitCombine And Lazarus and lazbuild itself is in ~/dev/lazarus/2.2.4/ But not on path... Should I copy lazbuild to ~/bin where fpc also is located? Or invoke it like this: ~/dev/lazarus/2.2.4/lazbuild videosplitcmb.lpi

I tried to symlink lazbuild into $HOME/bin and then inside the project dir I tried this:

$ lazbuild videosplitcmb.lpi
Error: (lazarus) invalid Lazarus directory "": directory lcl not found Error: (lazarus) Building failed: videosplitcmb.lpi

I tried lazbuild --help and found out that there is an option one can enter too:

lazbuild --lazarusdir=/home/bosse/dev/lazarus/2.2.4 videosplitcmb.lpi

And this time it worked fine!
I now have the modified tool and I moved it to the Ubuntu Server where it works just fine.

Thanks for the instruction on how to do it.

Bo Berglund Developer in Sweden

Reply by email

Guillermo Martínez Jiménez
to Bo Berglund: I have written a command line utility program on Linux using Lazarus as the IDE. This was…

Use FPC from command line is easy if you're not using the LCL (the Lazarus Component Library).

If you're using the LCL they explained in the other answers, but if you just use the RTL then the easiest way is just calling FPC from the same directory you have the sources:

~$ fpc theprogram

That will compile the program at "theprogram.pas" with default configuration (the fpc.cfg file).

There are a lot of options you can see just with:

~$ fpc -h | more

In most cases I create directories "src/", "obj/" and "bin/" and then I use a bash script like this:

#!/bin/sh
# Debug (GDB).
OPTIONS='-O1 -gw3 -gl -vwn -Ci -Cr -Ct -CR -Co -Sa -gh' # Release.
# OPTIONS='-O3 -CX -XX -Xs -vw'
FLAGS="$OPTIONS -Sh -Si -l"
DIALECT='-MObjFPC'
UNITS='-Fusrc'
OUTPUT='-FUobj -FEbin'
FILE='src/programfile.pas'

FULL="$FLAGS $DIALECT $UNITS $OUTPUT $FILE"
fpc $FULL

I hope this helps.

Reply by email