Recent

Author Topic: console application does not work on ubuntu server  (Read 374 times)

altanbozoglu

  • New member
  • *
  • Posts: 9
console application does not work on ubuntu server
« on: November 12, 2019, 12:02:27 pm »
Hello there; I'm creating a new console application with Lazarus 2.0.4 ide and running it perfectly on my ubuntu 18.4 desktop computer (I don't add any code). Then, when I copy and run the compiled binnary file of the application to Ubuntu 18.4 server, I get the following error message. I send the binary file to the server via ftp and run it on ssh. Result: "Segmentation fault (core dumped)".

If I install fpc on the ubuntu server and compile the source code on the server, the console application works fine.(send the source code to the server via ftp)
Server-side fp-ide

Both machines are intel based and linux kernel versions are the same.
I haven't been able to solve this problem in the last week and a half and I'm stuck at this point.
There is no package in the Project Inspector on Lazarus ide. I did not understand that an empty console application created by Lazarus ide did not work on the server.
I've reviewed the following articles but couldn't find a solution for me.
I'd be grateful for the help.

https://wiki.lazarus.freepascal.org/Console_Mode_Pascal
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Built-console-app-on-Linux-but-won-t-run-on-another-Linux-machine-td4055440.html
https://forum.lazarus.freepascal.org/index.php?topic=20525.0
https://forum.lazarus.freepascal.org/index.php/topic,43727.0.html

Here is the code:
Code: Pascal  [Select]
  1. program testapp;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5.  
  6. uses
  7.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  8.   cthreads,
  9.   {$ENDIF}{$ENDIF}
  10.   Classes, SysUtils, CustApp
  11.   { you can add units after this };
  12.  
  13.  
  14. type
  15.   { TSeverConsoleTest }
  16.  
  17.   TSeverConsoleTest = class(TCustomApplication)
  18.   protected
  19.     procedure DoRun; override;
  20.   public
  21.     constructor Create(TheOwner: TComponent); override;
  22.     destructor Destroy; override;
  23.     procedure WriteHelp; virtual;
  24.   end;
  25.  
  26. { TSeverConsoleTest }
  27.  
  28. procedure TSeverConsoleTest.DoRun;
  29. var
  30.   ErrorMsg: String;
  31. begin
  32.   // quick check parameters
  33.   ErrorMsg:=CheckOptions('h', 'help');
  34.   if ErrorMsg<>'' then begin
  35.  //   ShowException(Exception.Create(ErrorMsg));
  36.     Terminate;
  37.     Exit;
  38.   end;
  39.  
  40.   // parse parameters
  41.   if HasOption('h', 'help') then begin
  42.     WriteHelp;
  43.     Terminate;
  44.     Exit;
  45.   end;
  46.  
  47.   { add your program here }
  48.  
  49.   // stop program loop
  50.   Terminate;
  51. end;
  52.  
  53. constructor TSeverConsoleTest.Create(TheOwner: TComponent);
  54. begin
  55.   inherited Create(TheOwner);
  56.   StopOnException:=True;
  57. end;
  58.  
  59. destructor TSeverConsoleTest.Destroy;
  60. begin
  61.   inherited Destroy;
  62. end;
  63.  
  64. procedure TSeverConsoleTest.WriteHelp;
  65. begin
  66.   { add your help code here }
  67.   writeln('Usage: ', ExeName, ' -h');
  68. end;
  69.  
  70. var
  71.   Application: TSeverConsoleTest;
  72. begin
  73.   Application:=TSeverConsoleTest.Create(nil);
  74.   Application.Title:='Test Application';
  75.   Application.Run;
  76.   Application.Free;
  77. end.  
« Last Edit: November 12, 2019, 01:37:48 pm by altanbozoglu »

Handoko

  • Hero Member
  • *****
  • Posts: 3234
  • My goal: build my own game engine using Lazarus
Re: console application does not work on ubuntu server
« Reply #1 on: November 12, 2019, 12:34:09 pm »
Hello altanbozoglu,
Welcome to the forum.

I think that happened because some required libraries weren't be found. But when installing FPC, the system will automatically installed the libraries it needed.

You can see what libraries are needed to run a program using ldd command:
https://www.howtoforge.com/linux-ldd-command/

schuler

  • Full Member
  • ***
  • Posts: 134
Re: console application does not work on ubuntu server
« Reply #2 on: November 12, 2019, 12:44:52 pm »
I've been using FPC+Linux for many years without any problem.

If ldd doesn't solve, I would check if your binary was created with the proper instruction set (TARGET). In Lazarus, have a look at Options / Compiler Options / Target Platform and check if you are eventually using settings that your CPU doesn't support.

In Options / Custom Options / All Options, check what -Cp you are using.

 

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #3 on: November 12, 2019, 01:06:10 pm »
Handoko thank you. I did not know the existence of such a tool. It looks like the "Dependency Walker" tool used on the Windows operating system. Very useful tool. But I'm afraid it didn't work for me. On the server and desktop, it gives me an output like this: "not a dynamic executable". This is normal because my empty consol application generates a single executable binary and does not link to any library. It only outputs text for the console.
« Last Edit: November 12, 2019, 03:38:03 pm by altanbozoglu »

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Re: console application does not work on ubuntu server
« Reply #4 on: November 12, 2019, 01:12:10 pm »
What does the file command tell you about the executable?
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #5 on: November 12, 2019, 01:22:01 pm »
 Sorry schuler. I changed it to explain my problem in more detail. I get an error when I run the binary file running on the desktop computer later on the server. Both computers have the same Intel processor and linux kernel versions.

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #6 on: November 12, 2019, 01:25:54 pm »
hello MarkMLl Command outputs are as follows;
~$ ls -l
-rwxrwxrwx 1 xuser xuser  780918 Nov 12 00:18 testapp
~$ file testapp
testapp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linkedd

Thaddy

  • Hero Member
  • *****
  • Posts: 9285
Re: console application does not work on ubuntu server
« Reply #7 on: November 12, 2019, 01:37:45 pm »
Can you compile and transfer a simple helloworld and try that first?
If that fails, plz report back. That would be useful information to test:
Code: Pascal  [Select]
  1. program hellomars;
  2. {$mode objfpc}
  3. begin
  4.   writeln('Hello, Mars!');
  5. end.
If that doesn't work, there is a problem but only if the processor families do not match (32/64) , otherwise it is a matter of dependencies.
This program must be run from a terminal window, of course...Lazarus won't open a terminal window for you automatically. (Much to my annoyance,)
« Last Edit: November 12, 2019, 01:41:59 pm by Thaddy »
also related to equus asinus.

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #8 on: November 12, 2019, 02:40:55 pm »
hello Thaddy unfortunately it didn't work. result: Segmentation fault (core dumped). Interestingly, there is no dependency for this simple code and it works on the terminal on my own computer (ubuntu 18.4 desktop), but if I send the binary file to the server (I mark the file as executable with chmod) and it will give an error if I try to start it.
« Last Edit: November 12, 2019, 02:43:48 pm by altanbozoglu »

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Re: console application does not work on ubuntu server
« Reply #9 on: November 12, 2019, 02:47:24 pm »
Run cksum on the binary on both computers to make sure it's not being mnagled in transit.
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #10 on: November 12, 2019, 03:32:24 pm »
Many Thanks MarkMLl; I understand the problem.

terminal output
on my pc: 3559130803 178976 basicprogram
on my Server: 510560456 179380 basicprogram
they are different.

If I send the executable binary file to the ftp server in zip, the result is: 3559130803 178976 basicprogram.

So I had to send files with binnary mode when transferring ftp. In text mode (filezilla is the default) if I send a binary file with ftp, the file is corrupted. I've always looked for the wrong place for 10 days. checksum check never occurred to me. Thank you very much again MarkMLl.
I hope this helps for people who are having this problem later.

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #11 on: November 12, 2019, 03:42:51 pm »
Thank you very much to everyone. This issue is resolved.

MarkMLl

  • Sr. Member
  • ****
  • Posts: 285
Re: console application does not work on ubuntu server
« Reply #12 on: November 12, 2019, 04:08:41 pm »
Pro-tip: switch to sftp which should be installed as part of ssh. Not only is it secure, but it assumes binary mode by default :-)
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

Thaddy

  • Hero Member
  • *****
  • Posts: 9285
Re: console application does not work on ubuntu server
« Reply #13 on: November 12, 2019, 05:19:21 pm »
Ergo: you can not send binaries in text mode.... Didn't you know that? FTP has to be in binary mode. Reason: in binary 0's are completely valid bytes.
also related to equus asinus.

altanbozoglu

  • New member
  • *
  • Posts: 9
Re: console application does not work on ubuntu server
« Reply #14 on: November 12, 2019, 06:50:34 pm »
markmll; now I tried sftp for the first time and saw it works great thank you again. I will now use sftp after that.

Thaddy; Yes you're right, I'll never forget this little detail anymore. I never thought Filezillan would send the binary file in text mode. The default file transfer type selected for Filezilla is "Automatic". I had to manually select this setting as "binary". I didn't know that.