Recent

Author Topic: [SOLVED] Firebird 3 client and portable crossplatform application  (Read 1074 times)

axline

  • New Member
  • *
  • Posts: 14
I'm trying to incorporate fbclient into a portable app for redistribution on major platforms (Unix/Windows).

Server: Firebird 3.0.7 x64,
Platforms:
Windows 10 x64 (works like a charm with just fbclient.dll),
Ubuntu Linux x64 (works only with 'firebird-dev' installed),
macOS Catalina (doesn't work at all).

Only Firebird client is needed (the app connects to a remote server).

I have libfbclient.so for Linux and libfbclient.dylib for macos (extracted from corresponding installers). Where do I put those dynamic libraries and what do I do to make the systems recognize them?

So far I had no success... All the examples I found on the internet are outdated and don't work any more. Does anybody have any experience with developing cross-platform portable apps with Firebird3? How do you bundle the client library?
« Last Edit: January 29, 2021, 06:45:40 pm by axline »

zoltanleo

  • Sr. Member
  • ****
  • Posts: 293
Re: Firebird 3 client and portable crossplatform application
« Reply #1 on: January 17, 2021, 06:49:21 pm »
Hi axline.

I do not know what you are trying to do, but I can give advice to read this article.
http://www.ibase.ru/inst_manual/#client

It is written in Russian, but with the help of a google translator it is quite easy to grasp its meaning.
Win10 LTSC x64/Deb 10 amd64/Darwin Cocoa:
Lazarus x32/x64 2.1(r.64226); FPC 3.3.1 (r.47808), FireBird 3.0.7

Sorry for my bad English, I'm using translator ;)

axline

  • New Member
  • *
  • Posts: 14
Re: Firebird 3 client and portable crossplatform application
« Reply #2 on: January 18, 2021, 02:40:40 am »
Thank you, zoltanleo. This article starts with '...sorry in advance to UNIX users' and I'm, unfortunately, one of them  :D

Just to clarify the question: I have a Firebird database sitting in the cloud. Also, I have a simple program written with Lazarus 2.0.8 x64 to communicate with that database. The program is just one executable file compiled under Windows, Ubuntu Linux and Catalina (so I have myprogram.exe, myprogram, myprogram.app).

I want to put those binaries on a flash drive along with the corresponding Firebird client. The goal is just to stick the drive in a PC, run the binary, and connect to the database.

On Windows, I just put fbclient.dll next to myprogram.exe, and it does the trick. I don't need anything else to do. The program starts, the library is loaded, I'm happy  :D

On Linux, putting libfbclient.so/libfbclient.so.2/libfbclient.so.3.0.7 doesn't work this way. The binary seeks for fbclient at '/usr/lib/'. But even if it's there something is wrong. Seems like some more files are needed (more dependencies) but I haven't figured it out yet, which ones. Does anybody have a list of *.so files for libfbclient.so to work? If I install the whole thing (firebird-dev) then everything is ok. But I would really like to avoid having to install any additional packages for my program to work.

On macOS, I tried putting libfbclient.dylib (and other libraries from the Firebird installation) inside of the app bundle. No luck. Then I tried to put the entire server as a framework inside of the bundle. Also, no luck. So the question is: how do I use libfbclient.dylib on macOS? How to bundle it with myprogram.app, and what else should be changed for the app to find it?

Hope this text clarifies my intentions  :o

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1278
  • Former Delphi 1-7, 10.2 User
Re: Firebird 3 client and portable crossplatform application
« Reply #3 on: January 18, 2021, 04:55:11 am »
On macOS, I tried putting libfbclient.dylib (and other libraries from the Firebird installation) inside of the app bundle. No luck. Then I tried to put the entire server as a framework inside of the bundle. Also, no luck. So the question is: how do I use libfbclient.dylib on macOS? How to bundle it with myprogram.app, and what else should be changed for the app to find it?

I would suggest you have a look at the Wiki, specifically my article on macOS Dynamic Libraries. It should provide the detailed information after which you seek.
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64455 3.3.1 r48688  macOS 11.2 aarch64 Xcode 12.4
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

zoltanleo

  • Sr. Member
  • ****
  • Posts: 293
Re: Firebird 3 client and portable crossplatform application
« Reply #4 on: January 18, 2021, 03:58:58 pm »
Hi axline.

I posed this question to Russian firebird developers here
https://www.sql.ru/forum/actualutils.aspx?action=gotomsg&tid=523729&msg=22265332

One of them (Vlad Khorsun aka hvlad) replied roughly as follows:
Quote
If I'm not confusing anything - it should be available for the libfbclient.so.2 loader (symlink) and should point to libfbclient.so.
You can put both files (.so and .so.2) next to the program binary, but before running it, set LD_LIBRARY_PATH and FIREBIRD to point to the .so directory.
Place the firebird.conf and .msg files in the same directory as the client library if necessary.

For Mac see
http://paulbeachsblog.blogspot.com/2019/09/firebird-3-embedded-on-macosx.html
http://paulbeachsblog.blogspot.com/2021/01/firebird-embedded-in-sandboxed-macos-app.html
Win10 LTSC x64/Deb 10 amd64/Darwin Cocoa:
Lazarus x32/x64 2.1(r.64226); FPC 3.3.1 (r.47808), FireBird 3.0.7

Sorry for my bad English, I'm using translator ;)

mig-31

  • Sr. Member
  • ****
  • Posts: 284
Re: Firebird 3 client and portable crossplatform application
« Reply #5 on: January 18, 2021, 05:11:20 pm »
Other way under Linux you can prepare rpm or deb installation package and add dependence on libfbclient package into it.
Lazarus 2.0.6 - CentOS 7.x, Mageia 7.1

devEric69

  • Sr. Member
  • ****
  • Posts: 433
Re: Firebird 3 client and portable crossplatform application
« Reply #6 on: January 18, 2021, 06:06:46 pm »
Hello,

Personally, I patch (patchelf binutil; thanks to xBSD) everything, i.e. I launch my project1 in a Terminal, and patch all until I encounter no more error. So, ...:
- I've patched my project1, indicating where the Firebird client library is.
- I've patched the Firebird client library.
- ...\...

I've created a *.deb (binary package installation), with the Pascal Lazpackager (Lazarus package), which I have adapted from Debreate.
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

axline

  • New Member
  • *
  • Posts: 14
Re: Firebird 3 client and portable crossplatform application
« Reply #7 on: January 18, 2021, 06:40:48 pm »
zoltanleo, mig-31, devEric69, thank a lot for your valuable advice!  8)

I did a major mistake before - had extracted libfbclient.so from the latest Firebird installer (3.0.7). It has some additional dependencies which 3.0.5 (the one currently available in Ubuntu repositories) doesn't have. Now my program runs absolutely portable on Linux. The program consists of just 2 files: myprogram (binary) and libfbclient.so.3.0.5.

I just used the TSQLDBLibraryLoader component to load libfbclient.so from the program's folder.
This did the trick (onCreate of the data module):

Code: Pascal  [Select][+][-]
  1. GlobalPath:=ExtractFilePath(Application.ExeName); //full path to exe
  2.        
  3. with SQLDBLibraryLoader1 do begin
  4.   {$IFDEF WINDOWS}
  5.        LibraryName:=GlobalPath+'fbclient.dll';
  6.   {$ENDIF}
  7.   {$IFDEF LINUX}
  8.        LibraryName:=GlobalPath+'libfbclient.so.3.0.5';
  9.   {$ENDIF}
  10.   {$IFDEF DARWIN}
  11.       // LibraryName:=GlobalPath+'libfbclient.dylib'; //doesn't work yet
  12.    {$ENDIF}
  13.      Enabled:=true;
  14. end;

Tested this on an absolutely fresh Mint 20 installation - worked like a charm!  :)

Now it's Catalina's turn...  %)
« Last Edit: January 18, 2021, 06:49:02 pm by axline »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 923
Re: Firebird 3 client and portable crossplatform application
« Reply #8 on: January 19, 2021, 12:01:51 am »
hello,
I just used the TSQLDBLibraryLoader component to load libfbclient.so from the program's folder.
here is why :
in the wiki of free pascal :
Quote
For SQLDB database connectors, at least recent FPC versions try to load some default library names, but may fail. Using SQLDBLibraryLoader, you can specify the exact filename to load.

SQLDBLibraryLoader needs to be called before loading/enabling TSQLConnection components.

Note that often you can do a similar thing by setting the library name for the TSQLConnection descendant you are using. This does depend on that TSQLConnection descendant supporting that functionality.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 923
Re: Firebird 3 client and portable crossplatform application
« Reply #9 on: January 20, 2021, 06:45:30 am »
hello,
I did a major mistake before - had extracted libfbclient.so from the latest Firebird installer (3.0.7). It has some additional dependencies which 3.0.5 (the one currently available in Ubuntu repositories) doesn't have. Now my program runs absolutely portable on Linux.
not a mistake, you can use the 3.0.7 version of firebird if you resolve the dependency errors :
here is how to install firebird client and embedded  version on Ubuntu 20.04
1)
create a firebird directory in your home directory
create a plugins directory in this new directory
from the firebird 3 download tar.gz file  extract the files libfbclient.so.3.0.x and libEngine12.so :
put the file libfbclient.so.3.0.x in the firebird directory
put the file libEngine12.so in the firebird/plugins directory (for embedded)
in the .profile file of your home directory add this line at this end of the file :
Quote
export FIREBIRD=/home/myusername/firebird

Example of use of embedded version of firebird3  in my example database in lazarus/examples/database/image_mushrooms

A) Modify the unit1.pas :
Code: Pascal  [Select][+][-]
  1. const
  2.   FirebirdDB='ImageTest.fdb'; //database file for Firebird  
       
and
Code: Pascal  [Select][+][-]
  1.   FUsingFirebird := true; // force Firebird first
  2.   if not(FUsingFirebird) then    
add a component TSQLDBLibraryLoader in the GUI of the project.
select the file libfbclient.so.3.0.7  for the LibraryName of the component
Enabled the component : if you have an error check the dependencies for the library libfbclient.so.3.0.7 (ldd command)

For example on Ubuntu 20.04 i have some dependencies error on libncurses5 and libtommath.so.0
to correct the dependencies :
Quote
sudo apt-get install libncurses5
sudo ln -s /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0
if all is good you must have something like this :
Quote
~/firebird$ ldd libfbclient.so.3.0.7
   linux-vdso.so.1 (0x00007fff25dda000)
   librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f2687d60000)
   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f2687d5a000)
   libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007f2687d34000)
   libtommath.so.0 => /lib/x86_64-linux-gnu/libtommath.so.0 (0x00007f2687d15000)
   libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2687b34000)
   libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f26879e5000)
   libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f26879c8000)
   libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f26879a5000)
   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f26877b3000)
   /lib64/ld-linux-x86-64.so.2 (0x00007f2688160000)
   libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5
   
Enable the TSQLDBLibraryLoader component

Run the program : if you have an exception error on  not existing database file don't worry! click on continue, the database file will be recreated from the backup file (.fbk).

Result in Attachment

For windows :
create a firebird directory in a dev directory (ex: D:\Dev)
create a plugins directory in this new directory
from the firebird 3 download zip file  extract the files
fbclient.dll, icu*, engine12.dll
 :
put the files fbclient.dll, icu* in the firebird directory
put the file engine12.dll in the firebird/plugins directory (for embedded)
install the msvcrt libraries with the installer : system32\vccrt10_x64.msi

for the libraryName property of the TSQLDBLibraryLoader component select fbclient.dll


Friendly, J.P
« Last Edit: January 20, 2021, 07:57:36 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

devEric69

  • Sr. Member
  • ****
  • Posts: 433
Re: Firebird 3 client and portable crossplatform application
« Reply #10 on: January 20, 2021, 09:45:42 am »
For example on Ubuntu 20.04 i have some dependencies error on libncurses5 and libtommath.so.0
to correct the dependencies :
Quote
sudo apt-get install libncurses5
sudo ln -s /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0

For information, another way to get rid of the soname libtommath.so.0's backward compatibility, is to issue commands like this...:

Code: Bash  [Select][+][-]
  1. readelf -d libfbclient.so.3.0.5

...with a result that indicates that it's indeed necessary to patch libfbclient.so.3.0.5 (for example) like this:

Code: Bash  [Select][+][-]
  1. patchelf --remove-needed libtommath.so.0 libfbclient.so.3.0.5
  2. patchelf --add-needed libtommath.so.1 libfbclient.so.3.0.5
« Last Edit: January 21, 2021, 09:54:29 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

mariuz

  • New Member
  • *
  • Posts: 41
    • http://flamerobin.org
Re: Firebird 3 client and portable crossplatform application
« Reply #11 on: January 29, 2021, 09:50:26 am »
I'm trying to incorporate fbclient into a portable app for redistribution on major platforms (Unix/Windows).

Server: Firebird 3.0.7 x64,
macOS Catalina (doesn't work at all).



Maybe this article may help with macos and firebird embedded https://paulbeachsblog.blogspot.com/2021/01/firebird-embedded-in-sandboxed-macos-app.html
Also you need to install the server for the client libs even on macos https://www.firebirdsql.org/en/firebird-3-0/

axline

  • New Member
  • *
  • Posts: 14
Re: Firebird 3 client and portable crossplatform application
« Reply #12 on: January 29, 2021, 06:45:15 pm »
wow, so many useful things! Thanks a lot, guys!  8-) 8-)

Ok, I've made some progress with macOS (Catalina and Big Sur in my case).

So I downloaded this package: http://www.ibphoenix.com/downloads/MacEmbedded3x64.tar.gz, and extracted libfbclient.dylib from it (ver 3.0.4). The latest ver. 3.0.7 has some additional requirements (so more dynamic libraries). My point was to keep it as simple as possible: just the binary and a FB client next to it.

I placed libfbclient.dylib on the Desktop and did the following in the terminal:
Code: Pascal  [Select][+][-]
  1. cd Desktop
  2. sudo install_name_tool libfbclient.dylib -id @executable_path/libfbclient.dylib
  3.  

Then I just copied newly patched libfbclient.dylib next to the executable. If you work with bundles (e.g. myapp.app) it should be placed in /Contents/MacOS/libfbclient.dylib

That's pretty much it! Now this code works on all three platforms:
Code: Pascal  [Select][+][-]
  1.     GlobalPath:=ExtractFilePath(Application.ExeName); //full path to exe
  2.            
  3.     with SQLDBLibraryLoader1 do begin
  4.       {$IFDEF WINDOWS}
  5.            LibraryName:=GlobalPath+'fbclient.dll';
  6.       {$ENDIF}
  7.       {$IFDEF LINUX}
  8.            LibraryName:=GlobalPath+'libfbclient.so.3.0.5';
  9.       {$ENDIF}
  10.       {$IFDEF DARWIN}
  11.           LibraryName:=GlobalPath+'libfbclient.dylib';
  12.        {$ENDIF}
  13.          Enabled:=true;
  14.     end;
  15.  

Here I experimented just with the client as I didn't need the full embedded server. I tested my app on clean virtual machines running Windows 10, Linux Mint (18-20), MacOS Catalina & Big Sur - so far so good!

 

TinyPortal © 2005-2018