[SOLVED] Firebird 3 client and portable crossplatform application lazarus / 16-Databases ---------------------------------------------------------------------- axline · 2021-01-17 14:37 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? ---------------------------------------------------------------------- zoltanleo · 2021-01-17 17:49 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. ---------------------------------------------------------------------- axline · 2021-01-18 01:40 Thank you, zoltanleo. This article starts with '...sorry in advance to UNIX users' and I'm, unfortunately, one of them  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  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 ---------------------------------------------------------------------- trev · 2021-01-18 03:55 Quote from: axline on January 18, 2021, 02:40:40 amOn 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. ---------------------------------------------------------------------- zoltanleo · 2021-01-18 14:58 Hi axline. I posed this question to Russian firebird developers here https://www.sql.ru/forum/actualutils.aspx?action=gotomsg&tid=523729&ms g=22265332 One of them (Vlad Khorsun aka hvlad) replied roughly as follows: QuoteIf 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 ---------------------------------------------------------------------- mig-31 · 2021-01-18 16:11 Other way under Linux you can prepare rpm or deb installation package and add dependence on libfbclient package into it. ---------------------------------------------------------------------- devEric69 · 2021-01-18 17:06 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. ---------------------------------------------------------------------- axline · 2021-01-18 17:40 zoltanleo, mig-31, devEric69, thank a lot for your valuable advice!  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i GlobalPath:=ExtractFilePath(Application.ExeName); //full path to exe      with SQLDBLibraryLoader1 do begin  {$IFDEF WINDOWS}       LibraryName:=GlobalPath+'fbclient.dll';  {$ENDIF}  {$IFDEF LINUX}     LibraryName:=GlobalPath+'libfbclient.so.3.0.5';  {$ENDIF}  {$IFDEF DARWIN}      // LibraryName:=GlobalPath+'libfbclient.dylib'; //doesn't work yet   {$ENDIF}     Enabled:=true;end; Tested this on an absolutely fresh Mint 20 installation - worked like a charm!  Now it's Catalina's turn... ---------------------------------------------------------------------- Jurassic Pork · 2021-01-18 23:01 hello, Quote from: axline on January 18, 2021, 06:40:48 pmI just used the TSQLDBLibraryLoader component to load libfbclient.so from the program's folder. here is why : in the wiki of free pascal : QuoteFor 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 Pork · 2021-01-20 05:45 hello, Quote from: axline on January 18, 2021, 06:40:48 pmI 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 : Quoteexport 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  FirebirdDB='ImageTest.fdb'; //database file for Firebird         and Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   FUsingFirebird := true; // force Firebird first  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 : Quotesudo apt-get install libncurses5 sudo ln -s /usr/lib/x86_64-linux-gnu/libtommath.so.1 /usr/lib/x86_64-linux-gnu/libtommath.so.0if 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 ---------------------------------------------------------------------- devEric69 · 2021-01-20 08:45 Quote from: Jurassic Pork on January 20, 2021, 06:45:30 amFor example on Ubuntu 20.04 i have some dependencies error on libncurses5 and libtommath.so.0 to correct the dependencies : Quotesudo 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i patchelf --remove-needed libtommath.so.0 libfbclient.so.3.0.5patchelf --add- needed libtommath.so.1 libfbclient.so.3.0.5 ---------------------------------------------------------------------- mariuz · 2021-01-29 08:50 Quote from: axline on January 17, 2021, 03:37:05 pmI'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 · 2021-01-29 17:45 wow, so many useful things! Thanks a lot, guys!  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i cd Desktopsudo install_name_tool libfbclient.dylib -id @executable_path/libfbclient.dylib  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     GlobalPath:=ExtractFilePath(Application.ExeName); //full path to exe             with SQLDBLibraryLoader1 do begin      {$IFDEF WINDOWS}         LibraryName:=GlobalPath+'fbclient.dll';      {$ENDIF}      {$IFDEF LINUX}           LibraryName:=GlobalPath+'libfbclient.so.3.0.5';      {$ENDIF}      {$IFDEF DARWIN}          LibraryName:=GlobalPath+'libfbclient.dylib';       {$ENDIF}         Enabled:=true;    end; 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!