Recent

Author Topic: Differences between compiling from command-line and from Lazarus  (Read 1196 times)

z0rr0

  • New Member
  • *
  • Posts: 48
Hello, I am in Windows 10 using Lazarus with a fpc crosscompiler which targets Linux. I built this by using fpcupdeluxe. I can't compile my project from Lazarus, however, the same command-line works from bash. Do you know what is happening? The command-lines are:

Lazarus:
"C:\fpcupdeluxefortoromicrovm\fpc\bin\x86_64-win64\fpc.exe
-Tlinux
-MObjFPC
-Sc
-Cg
-O2
-kprt0.o
-veibq
-vw-n-h-
-FiC:\Users\Matias\Desktop\fpc-3.2.0\rtl\objpas\sysutils
-FiC:\Users\Matias\Desktop\fpc-3.2.0\rtl\linux\x86_64
-FiC:\Users\Matias\Desktop\fpc-3.2.0\rtl\x86_64
-FiC:\Users\Matias\Desktop\fpc-3.2.0\rtl\linux
-FiC:\Users\Matias\Desktop\fpc-3.2.0\rtl\inc
-FiC:\Users\Matias\Desktop\fpc-3.2.0\rtl\unix
-FuC:\Users\Matias\Desktop\torokernel\master-for-lazarus\rtl
-FuC:\Users\Matias\Desktop\torokernel\master-for-lazarus\rtl\drivers
-FuC:\Users\Matias\Desktop\fpc-3.2.0\rtl\linux
-FuC:\Users\Matias\Desktop\fpc-3.2.0\rtl\unix
-FuC:\Users\Matias\Desktop\fpc-3.2.0\rtl\objpas
-FuC:\Users\Matias\Desktop\fpc-3.2.0\rtl\inc
-FuC:\Users\Matias\Desktop\torokernel\master-for-lazarus\examples\HelloWorld\
-oC:\Users\Matias\Desktop\torokernel\master-for-lazarus\examples\HelloWorld\HelloWorld
-Cg-
-Si
HelloWorld.pas"

When I launch Compile from the editor the behavior varies. Sometime ends up with "sysnr.inc(21,1) Error: Internal error 200501156" and sometimes it can't find the correct ld for elf64. 
 
Bash:

"/C/fpcupdeluxefortoromicrovm/fpc/bin/x86_64-win64/fpc.exe \
-Tlinux \
-MObjFPC \
-Sc \
-Cg \
-O2 \
-kprt0.o \
-veibq \
-vw-n-h- \
-Fi"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\objpas\sysutils" \
-Fi"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\linux\x86_64" \
-Fi"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\x86_64" \
-Fi"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\linux" \
-Fi"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\inc" \
-Fi"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\unix" \
-Fu"C:\Users\Matias\Desktop\torokernel\master-for-lazarus\rtl" \
-Fu"C:\Users\Matias\Desktop\torokernel\master-for-lazarus\rtl\drivers" \
-Fu"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\linux" \
-Fu"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\unix" \
-Fu"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\objpas" \
-Fu"C:\Users\Matias\Desktop\fpc-3.2.0\rtl\inc" \
-Fu"C:\Users\Matias\Desktop\torokernel\master-for-lazarus\examples\HelloWorld" \
-o"C:\Users\Matias\Desktop\torokernel\master-for-lazarus\examples\HelloWorld\HelloWorld" \
-Cg- \
-Si \
HelloWorld.pas"

Thanks,

P.S.: I am using my own system.pp.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Differences between compiling from command-line and from Lazarus
« Reply #1 on: January 16, 2021, 02:56:45 pm »
RTL build is special, and not automatically done via lazarus.

Sometimes people get into trouble by trying to force lazarus (after e.g. fpcdeluxe) to also recompile the RTL, leading to multiple versions of core units, and nothing works anymore.

Easiest is to keep installs clean, and never ever force lazarus to rebuild the RTL till you have more experience.

Forcing the RTL to rebuild happens e.g. by adding the RTL SOURCE dirs to the compiler search path.

Another reason could be differing fpc.cfg files.

z0rr0

  • New Member
  • *
  • Posts: 48
Re: Differences between compiling from command-line and from Lazarus
« Reply #2 on: January 16, 2021, 03:25:47 pm »
Thanks marcov. I have no choice but to recompile the system, which is a modified version of Linux system for Toro kernel. If you know a better way to do it from Lazarus, do not hesitate to let me know.   

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Differences between compiling from command-line and from Lazarus
« Reply #3 on: January 16, 2021, 05:02:54 pm »
Thanks marcov. I have no choice but to recompile the system, which is a modified version of Linux system for Toro kernel. If you know a better way to do it from Lazarus, do not hesitate to let me know.

You should best compile your RTL separately from your final program. It might work to put it in a separate package and depend on it from your main application, but otherwise you should compile your RTL from the command line and only use the compiled units.
It might also help to pass the -n option which prohibits FPC from using its default fpc.cfg which might throw a wrench into things for your RTL.

z0rr0

  • New Member
  • *
  • Posts: 48
Re: Differences between compiling from command-line and from Lazarus
« Reply #4 on: January 17, 2021, 06:31:15 pm »
Hello and thanks for the answers. It works by:
1. Putting all the RTL units in the same directory of the program
2. Overwriting the ld.exe by the ld.exe from the cross-compilator.

The second step is not required when compiling from the command-line. It only requires to use "-TLinux". When compiling from Lazarus, the binary is x3 bigger than from the command line. The size of the binary from the command-line and in Linux is the same. The first step is not very practical so I have to figure out how to workaround.

z0rr0

  • New Member
  • *
  • Posts: 48
Re: Differences between compiling from command-line and from Lazarus
« Reply #5 on: January 17, 2021, 08:45:17 pm »
I somehow fixed my problem by adding '-B-' in the project options, removing '-n', and putting the RTL in the program's directory. By doing this, Lazarus finds the correct ld and generates the correct binary. I would like to avoid the copying of the RTL in the program directory. 
« Last Edit: January 17, 2021, 10:33:03 pm by z0rr0 »

 

TinyPortal © 2005-2018