Recent

Author Topic: [solved] not compiling with dbus  (Read 5391 times)

chrigr

  • New member
  • *
  • Posts: 5
[solved] not compiling with dbus
« on: February 21, 2019, 10:49:05 am »
Hi Folks,

there is an old project, which needs a dbus-integration. The project itself compiles as always on:

- Lazarus 1.2.4 with FPC 2.6.4  Raspbian Jessy (I believe)
- Lazarus 1.8.2 with FPC 3.0.0 (via apt-get) on Raspbian Stretch 
- Lazarus 2.0.0 RC3 with FPC 3.0.4  (self compiled) on Raspbian Stretch

As soon as I try to compile my project with the inclusion of "dbus" - I get a linking error EXCEPT on the old system!
Problem is: I have to use the new Raspian as the software im intending to communicate over dbus with requires Qt5

Can somebody please try to compile the example code from https://github.com/graemeg/freepascal/blob/master/packages/dbus/examples/busexample.pp on a Raspberry 3 with raspbian and tell me if it compiles for them?
I'm starting to get grey hair over this issue.

Or is "dbus" already deprecated?
Is there an alternative? Am I missing something?
« Last Edit: February 28, 2019, 02:13:45 pm by chrigr »

chrigr

  • New member
  • *
  • Posts: 5
Re: not compiling with dbus
« Reply #1 on: February 25, 2019, 11:18:07 am »
no luck so far.

Could anybody just do me a small favor and try to compile a FPC-Project using a recent lazarus and FPC installation - and tell me if the inclusion of the "dbus" package into the main does anything unusual for them? Not necessarily on an ARMHF Linux - whatever you usually run on.

would be great, thanks!

Thaddy

  • Hero Member
  • *****
  • Posts: 10993
Re: not compiling with dbus
« Reply #2 on: February 25, 2019, 11:57:24 am »
I got it working after I did this (mind the path and the sudo, but you probably have the same configuration as me!)
Code: Bash  [Select][+][-]
  1. pi@raspberrypi:/lib/arm-linux-gnueabihf $ sudo cp libdbus-1.so.3 libdbus-1.so
After that the code compiles as before.
Code: Bash  [Select][+][-]
  1. fpc  -Fl/usr/lib/gcc/arm-linux-gnueabihf/6.3.0 -Fu/usr/local/lib/fpc/3.3.1/units/* -Fi/home/pi/synapse/* -CX -XXs -O4 "busexample.pas" (in directory: /home/pi)
  2. Free Pascal Compiler version 3.3.1-r41411 [2019/02/22] for arm
  3. Copyright (c) 1993-2018 by Florian Klaempfl and others
  4. Target OS: Linux for ARMHF
  5. Compiling busexample.pas
  6. busexample.pas(134,49) Warning: Local variable "sigvalue" does not seem to be initialized
  7. busexample.pas(194,8) Note: Local variable "reply" not used
  8. busexample.pas(195,3) Note: Local variable "args" not used
  9. busexample.pas(196,3) Note: Local variable "param" not used
  10. busexample.pas(323,43) Warning: Local variable "level" does not seem to be initialized
  11. busexample.pas(323,30) Warning: Local variable "stat" does not seem to be initialized
  12. Linking busexample
  13. 358 lines compiled, 1.2 sec
  14. 3 warning(s) issued
  15. 3 note(s) issued
  16. Compilation finished successfully.
  17.  
Note those warnings need to be fixed....

And I should actually have created a symlink instead, but this also works (it is a copy of the symlink  8-) O:-) )

There's probably a bit more to do given this:
Code: Bash  [Select][+][-]
  1. Syntax: dbus-example [send|receive|listen|query] [<param>]
  2. process 3376: Applications must not close shared connections - see dbus_connection_close() docs. This is a bug in the application.

But on correct use it works without that message from dbus.

I already fixed the warnings, but after I fix (2) above I will submit a patch.

But if you do a cp as per my first you'll be fine.
« Last Edit: February 25, 2019, 01:16:58 pm by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

Thaddy

  • Hero Member
  • *****
  • Posts: 10993
Re: not compiling with dbus
« Reply #3 on: February 25, 2019, 01:44:17 pm »
I noticed you didn't tell the whole  truth btw < >:D;D :D
Quote
here is an old project, which needs a dbus-integration. The project itself compiles as always on:

- Lazarus 1.2.4 with FPC 2.6.4  Raspbian Jessy (I believe)
- Lazarus 1.8.2 with FPC 3.0.0 (via apt-get) on Raspbian Stretch 
- Lazarus 2.0.0 RC3 with FPC 3.0.4  (self compiled) on Raspbian Stretch
true  "- Lazarus 1.2.4 with FPC 2.6.4  Raspbian Jessy (I believe)"
false "- Lazarus 1.8.2 with FPC 3.0.0 (via apt-get) on Raspbian Stretch" 
false "- Lazarus 2.0.0 RC3 with FPC 3.0.4  (self compiled) on Raspbian Stretch"
 
It fails because the default so symlink is missing on stretch, not because a bug on the Freepascal side... as proven by my solution. Be more careful in the future....
You can file a bug report to that extend to Raspbian if you wish.
Did you do a re-install or apt-get dist-upgrade in the mean time? A dist-upgrade would leave the default symlink, but a re-install removes it. (both of them will fail, since the symlink points to oblivion afakt)
« Last Edit: February 25, 2019, 01:59:55 pm by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

chrigr

  • New member
  • *
  • Posts: 5
Re: not compiling with dbus
« Reply #4 on: February 27, 2019, 12:00:22 pm »
Thanks for your help!
I got it running.


Regarding my text:
My old code was compiling with all those configs.

But as soon as I included "dbus" (to my old code) it only compiled on my old config


Im running in a different problem now, it seems to be a more general dbus issue.
I can't append a boolean to a dbus message.


Code: Pascal  [Select][+][-]
  1. procedure BusCall(value1: LongWord; value2: Boolean);
  2. var
  3.   err: DBusError;
  4.   conn: PDBusConnection;
  5.   msg: PDBusMessage;
  6.   args: DBusMessageIter;
  7.   pending: PDBusPendingCall;
  8.  
  9. begin
  10.  
  11.   msg := dbus_message_new_method_call(TARGET,
  12.                                       PATH,
  13.                                       DBINTERFACE,
  14.                                       METHODNAME);    
  15.  
  16.   dbus_message_iter_init_append(msg, @args);
  17.     if (dbus_message_iter_append_basic(@args, DBUS_TYPE_UINT32, @value1) = 0) then
  18.   begin
  19.     F_main.Label8.Caption:='Could not append Value1';
  20.     Exit;
  21.   end;
  22.   if (dbus_message_iter_append_basic(@args, DBUS_TYPE_BOOLEAN, @value2) = 0) then
  23.   begin
  24.     F_main.Label8.Caption:='Could not append Value2';
  25.     Exit;
  26.   end;
  27.  

This code works if I use two UINT32 but as soon as I try to append the Boolean it exits.

In general everything is working nicely, i can communicate over the dbus and have startet rewriting the sample code for my purposes. But I somehow need to get this Boolean in there to call a specific method.


In another part of the example code they are appending an boolean - so my general path seems to be correct:
Code: Pascal  [Select][+][-]
  1. rocedure reply_to_method_call(msg: PDBusMessage; conn: PDBusConnection);
  2. var
  3.   reply: PDBusMessage;
  4.   args: DBusMessageIter;
  5.   stat: Boolean = true;
  6.   level: dbus_uint32_t = 21614;
  7.   serial: dbus_uint32_t = 0;
  8.   param: PChar = '';
  9. begin
  10.    // read the arguments
  11.    if (dbus_message_iter_init(msg, @args) = 0) then
  12.       WriteLn('Message has no arguments!')
  13.    else if (DBUS_TYPE_STRING <> dbus_message_iter_get_arg_type(@args)) then
  14.       WriteLn('Argument is not string!')
  15.    else
  16.       dbus_message_iter_get_basic(@args, @param);
  17.  
  18.    WriteLn('Method called with ', param);
  19.  
  20.    // create a reply from the message
  21.    reply := dbus_message_new_method_return(msg);
  22.  
  23.    // add the arguments to the reply
  24.    dbus_message_iter_init_append(reply, @args);
  25.    if (dbus_message_iter_append_basic(@args, DBUS_TYPE_BOOLEAN, @stat) = 0) then
  26.    begin
  27.      WriteLn('Out Of Memory!');
  28.      Exit;
  29.    end;
  30.    if (dbus_message_iter_append_basic(@args, DBUS_TYPE_UINT32, @level) = 0) then
  31.    begin
  32.      WriteLn('Out Of Memory!');
  33.      Exit;
  34.    end;          




I also tried using
Code: Pascal  [Select][+][-]
  1. dbus_message_append_args()
as described here:
https://dbus.freedesktop.org/doc/api/html/group__DBusMessage.html#ga591f3aab5dd2c87e56e05423c2a671d9

And it should be as easy as that:
Code: Pascal  [Select][+][-]
  1. dbus_message_append_args (msg,
  2.                           DBUS_TYPE_UINT32, @value1,
  3.                           DBUS_TYPE_BOOLEAN, @value2,
  4.                           DBUS_TYPE_INVALID);  


buuuuuuuut:
Quote
busexample.pas(297,1) Error: Wrong number of parameters specified for call to "dbus_message_append_args"
busexample.pas(498) Fatal: There were 1 errors compiling module, stopping
« Last Edit: February 27, 2019, 12:03:26 pm by chrigr »

Thaddy

  • Hero Member
  • *****
  • Posts: 10993
Re: not compiling with dbus
« Reply #5 on: February 27, 2019, 01:20:06 pm »
The Boolean type for dbus is one of the bool versions, not the pascal boolean types.
See the language reference guide: https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-270003.1.1
The difference is important here and in this case type longbool.
E.g.:
Code: Pascal  [Select][+][-]
  1. stat: longbool = true;
since we are interfacing with a library written in C.
Pascal Booleans are strictly 0 or 1.
C bools are 0 or not zero (any value except zero represents true.)
« Last Edit: February 27, 2019, 01:23:56 pm by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

chrigr

  • New member
  • *
  • Posts: 5
Re: not compiling with dbus
« Reply #6 on: February 27, 2019, 01:50:08 pm »
Brilliant!
Thank you so much!

Thaddy

  • Hero Member
  • *****
  • Posts: 10993
Re: not compiling with dbus
« Reply #7 on: February 27, 2019, 02:37:17 pm »
Brilliant!
Thank you so much!
That leaves me flabbergasted how you did get the older versions working under Stretch, since it is an omission on the Raspbian side not to provide that symlink.... 8-)
Anyway, I tested my adaptions and they indeed pass all tests now.
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

chrigr

  • New member
  • *
  • Posts: 5
Re: not compiling with dbus
« Reply #8 on: February 27, 2019, 03:30:59 pm »
Brilliant!
Thank you so much!
That leaves me flabbergasted how you did get the older versions working under Stretch, since it is an omission on the Raspbian side not to provide that symlink.... 8-)
Anyway, I tested my adaptions and they indeed pass all tests now.


Oh, I forgot about that.

I needed a solution and was kind of desperate so I went ahead and did the following to my poor Raspbian jessie:  🙈
- modified my sourcelist to use stretch-repo
- apt-get update
- apt-get upgrade

After that I still had my old Lazarus and FPC version - but was able to install the Qt5-based service I'm communicating with now

I'm going to try again with a fresh compile of Lazarus on a Strecht sooon..ish
« Last Edit: February 27, 2019, 03:39:02 pm by chrigr »

Thaddy

  • Hero Member
  • *****
  • Posts: 10993
Re: not compiling with dbus
« Reply #9 on: February 27, 2019, 03:38:18 pm »
I see. That leaves the symlink intact, as I suspected. Anyway: it does work now for me. Let me know if there's more.
(btw: its not poor: RPi3's are damned good hardware and outperforming budget quad core Intels, )
« Last Edit: February 27, 2019, 03:42:55 pm by Thaddy »
The average programmer productivity is 4-5 hours per day. Peak performance 72 hours for short bursts. MTBF is 1 second or less.

chrigr2

  • Newbie
  • Posts: 1
Re: [solved] not compiling with dbus
« Reply #10 on: June 25, 2021, 11:56:11 am »
An hour ago, I stumbled across this useful thread.
5 min ago I realized that it was me how started it   :-[

This project was paused for ......... quite a whilte. And I was able to use the same trick posted by Thaddy
Code: Pascal  [Select][+][-]
  1. pi@raspberry:/lib/i386-linux-gnu $ sudo cp libdbus-1.so.3 libdbus-1.so

to compile a project that includes dbus on
- Raspbian Buster Desktop i386 running in a VM using
- a fpcdeluxe installed
- Lazarus 2.0.12 and
- FPC 3.2.2

so I guess my specific bug from 2019 is still present.

HOWEVER, I want to use this VM to cross compile for Raspberry Pi as well using, which so far worked flawless - but trying to include dbus I've encountered a new problem.

I've tried to solve this error:
Code: Pascal  [Select][+][-]
  1. Debug: /home/pi/fpcupdeluxe/cross/bin/arm-linux/arm-linux-gnueabihf-ld: cannot find -ldbus-1

by replicating the solution I did for the i386 compiling project and doing:
Code: Pascal  [Select][+][-]
  1. pi@raspberry:~/fpcupdeluxe/cross/lib/arm-linux $ sudo cp libdbus-1.so.3 libdbus-1.so

This unfortunately results in another error when I try to cross compile for armhf linux:

Code: Pascal  [Select][+][-]
  1. Compile Project, Mode: ARM, CPU: arm, Target: VM_test_arm: Exit code 1, Errors: 1, Hints: 2
  2. Hint: Start of reading config file /home/pi/fpcupdeluxe/fpc/bin/i386-linux/fpc.cfg
  3. Hint: End of reading config file /home/pi/fpcupdeluxe/fpc/bin/i386-linux/fpc.cfg
  4. Verbose: Free Pascal Compiler version 3.2.2-r49371 [2021/06/23] for arm
  5. Verbose: Copyright (c) 1993-2021 by Florian Klaempfl and others
  6. Verbose: Target OS: Linux for ARMHF
  7. Verbose: Compiling VM_test.lpr
  8. Verbose: Compiling resource /media/git_ARM_PI_VM_test/lib/arm-linux/VM_test.or
  9. Verbose: Linking /media/git_ARM_PI_VM_test/VM_test_arm
  10. Debug: /home/pi/fpcupdeluxe/cross/bin/arm-linux/arm-linux-gnueabihf-ld: warning: libsystemd.so.0, needed by /home/pi/fpcupdeluxe/cross/lib/arm-linux//libdbus-1.so, not found (try using -rpath or -rpath-link)
  11. Debug: /home/pi/fpcupdeluxe/cross/bin/arm-linux/arm-linux-gnueabihf-ld: /home/pi/fpcupdeluxe/cross/lib/arm-linux//libdbus-1.so: undefined reference to `sd_listen_fds@LIBSYSTEMD_209'
  12. Debug: /home/pi/fpcupdeluxe/cross/bin/arm-linux/arm-linux-gnueabihf-ld: /home/pi/fpcupdeluxe/cross/lib/arm-linux//libdbus-1.so: undefined reference to `sd_is_socket@LIBSYSTEMD_209'
  13. VM_test.lpr(43,1) Error: Error while linking
  14. VM_test.lpr(43,1) Verbose: There were 1 errors compiling module, stopping
  15. Verbose: Compilation aborted
  16. Verbose: /home/pi/fpcupdeluxe/fpc/bin/i386-linux/ppcrossarm returned an error exitcode


Any help is highly appreciated as I'm stuck for a while now trying to solve this
« Last Edit: June 25, 2021, 11:58:43 am by chrigr2 »

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1512
Re: [solved] not compiling with dbus
« Reply #11 on: June 25, 2021, 12:38:41 pm »
Fpcupdeluxe uses its own libs when cross-compiling towards another arch, if it cannot find suitable libs on your system. As is the case in your setup.
These libs are getting old.
If you happen to be in need of an extra lib (dbus), and you obtain it from your current arm-system, this extra lib will definitely need other recent libs also, to solve its dependencies.
As is the case in your setup.
Best practice:
Copy the (all) libs from your current arm-system into the cross-libs directory of fpcupdeluxe. That way, the libs are compatible with each other and linking will succeed.

 

TinyPortal © 2005-2018