[SOLVED] How to distribute a 64-bit and 32-bit version of SQLite with my program lazarus / 16-Databases ---------------------------------------------------------------------- Gizmo · 2017-11-14 17:04 I've read this (http://forum.lazarus.freepascal.org/index.php?topic=35362.0) and a few other threads (http://forum.lazarus.freepascal.org/index.php?topic=19238.0) but up- to-date direction still seems to be evading me. I've re-written a program of mine to use SQLite and for the Windows side, it's working great. I have the Windows SQLIte DLL in the same folder as the compiled exe, and it works fine. I have the following compiler ifdef in my code: 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 {$IFDEF Windows}       // Ensure we're using the local sqlite3.dll for Windows       SQLiteDefaultLibrary := 'sqlite3.dll';     {$ENDIF}     {$IFDEF Darwin}         SQLiteDefaultLibrary := 'sqlite3-osx'; // Use an OSX version of SQLite       {$else}         {$IFDEF UNIX and !$ifdef Darwin}           SQLiteDefaultLibrary := 'sqlite3-linux'; // Use a Linux version of SQLite.          {$ENDIF}     {$ENDIF}  if FileExists(SQLiteDefaultLibrary) then     begin       // Set the filename of the sqlite database       SQLite3Connection1.DatabaseName := 'DBName.sqlite';       // Create the database       CreateDatabase(SQLite3Connection1.DatabaseName); // THROWS ERROR HERE       if SQLIte3Connection1.Connected then lblConnectionStatus.Caption:= 'SQLite3 Database connection active';    end       else ShowMessage('Cannot create SQLite database. Ensure an SQLite.dll or equivalent file exists');  So when I ran this on my Linux system last night, I got QuoteProject raised exception class 'EInOutError' with message: Can not load SQLite client library "sqlite-linux". Check your installation The line that triggers that error is in another procedure where my program creates a new SQLite database. The line "SQLite3Connection1.Open" is what throws it, and no new database file is created. Suggesting it can't connect to, or even create, the new database. Yet the same code on Windows creates a new sqlite database file. I am running 64-bit Linux Mint 17 and Lazarus 1.6.4 and FPC 3.0.2, installed via the deb packages for 64-bit Linux systems. The SQLite compiled binary I am using is from http://sqlite.org/2017/sqlite- tools-linux-x86-3210000.zip. There only seems to be one compiled version for Linux, which I suspect may be the issue....i.e. the version is perhaps compiled for 32-bit Linux and not 64 bit Linux, but the fact they have only provided the one made me assume it was generic that would work on both.  Anyway, what I want to know is, given that most Linux distros have SQLite installed anyway, how can I fairly reliably code my program to look for the users copy of SQLite and then use that. Or, better still, how can I package a 64-bit and 32-bit version of SQLite for inclusion with my compiled binary? Or is this error related to something else entirely!!? Many thanks ---------------------------------------------------------------------- Gizmo · 2017-11-16 14:41 OK. SQLiteDefaultLibrary I notice is a variable (https://github.com/graemeg/freepascal/blob/master/packages/fcl- db/src/sqldb/sqlite/sqlite3conn.pp). Does it somehow lookup the path to the default sqlite program on whatever host it is running? So do I need to specify a file at all? Alternatively, given that SQLIte is distributed with most modern Linux distributions anyway, what way are people using to lookup the SQLIte path for the distro in which their program finds itself running? How do the likes of Firefox and Chrome achieve this. Both of which use SQLIte massively. ---------------------------------------------------------------------- molly · 2017-11-16 15:53 hi Gizmo, Perhaps this wiki-page and this thread might be able to help you out a bit. ---------------------------------------------------------------------- mig-31 · 2017-11-16 16:11 It's simple. There is POSIX standard = sqlite.so must be is in /usr/lib 32-bit and /usr/lib64 ---------------------------------------------------------------------- molly · 2017-11-16 16:27 In addition to mig-31's answer have a look at this wiki article. That's why i mentioned TSQLDBLibraryLoader, e.g. for those cases that you disagree with (or for whatever reason, can't use) the order as described. ---------------------------------------------------------------------- Gizmo · 2017-11-20 22:11 Thanks guys. So, to simply bundle and use pre-compiled binaries that I ship with the exe, would this work and be sensible or a bad idea? Code: [Select]  SQLDBLibraryLoader1.ConnectionType:='SQLite3';   {$ifdef windows}     SQLDBLibraryLoader1.LibraryName := 'sqlite-win.dll'; {$else}   {$ifdef darwin}      SQLDBLibraryLoader1.LibraryName := 'sqlite-osx';   {$else}     SQLDBLibraryLoader1.LibraryName := 'sqlite-linux';   {$endif} {$endif}   SQLDBLibraryLoader1.Enabled := true;   SQLDBLibraryLoader1.LoadLibrary; ---------------------------------------------------------------------- molly · 2017-11-20 23:58 @Gizmo: afaik the safest way would be to use full path names, since you are shipping your own you also know where they are located exactly. You could even opt for a config file that allows to override your 'static' used defaults. PS: if i remember correctly then the loadlibrary method is called automatically when enabled is set to true (even though the wiki calls this method explicitly in the example). ---------------------------------------------------------------------- Gizmo · 2017-11-21 23:30 Thank you Molly, for the tip re SQLDBLibraryLoader. Using three instances of that for each OS (to save a single one being adjusted when compiled on different platforms), I've created a working cross platform system that can utilise SQLite, without any fellow coders having to reconfigure the SQLDBLibraryLoader object . Try as I might, I couldn't get local downloaded pre-compiled versions to work with Linux and OSX. So by querying the default paths on both platforms, and given that both pretty much all (at least most) modern Linux distros and OSX versions come with SQLite, the code below should work for most users I hope. It works on all three of my systems anyway. For Windows users, I ship the DLL. 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 {$ifdef windows}    SQLDBLibraryLoaderWindows.ConnectionType:='SQLite3';    if FileExists('sqlite3-win.dll') then    begin      SQLDBLibraryLoaderWindows.LibraryName := 'sqlite3-win.dll';      SQLDBLibraryLoaderWindows.Enabled := true;      SQLDBLibraryLoaderWindows.LoadLibrary;      // Set the filename of the sqlite database      SQLite3Connection1.DatabaseName := 'QuickHashDBWin.sqlite';      // Create the database      CreateDatabase(SQLite3Connection1.DatabaseName);      if SQLIte3Connection1.Connected then lblConnectionStatus.Caption:= 'SQLite3 Database connection active';    end    else    begin      ShowMessage('Cannot create SQLite database. Ensure you extracted the sqlite-win.dll file from the zip file');      exit;    end;  {$else}  {$ifdef darwin}    SQLDBLibraryLoaderOSX.ConnectionType:='SQLite3';  // OSX sqlite file is a dynamic lib libsqlite3.dylib     if FileExists('/usr/lib/libsqlite3.dylib') then    begin      SQLDBLibraryLoaderOSX.LibraryName := '/usr/lib/libsqlite3.dylib';    SQLDBLibraryLoaderOSX.Enabled := true;      SQLDBLibraryLoaderOSX.LoadLibrary;      // Set the filename of the sqlite database      SQLite3Connection1.DatabaseName := 'QuickHashDBOSX.sqlite';      // Create the database      CreateDatabase(SQLite3Connection1.DatabaseName);      if SQLIte3Connection1.Connected then lblConnectionStatus.Caption:= 'SQLite3 Database connection active';    end    else    begin      ShowMessage('Cannot create SQLite database. Is SQLite installed?');    exit;    end;    {$else}     // If it's 64-bit Linux, use the 64-bit SQLite3 install    if FileExists('/usr/lib/x86_64-linux- gnu/libsqlite3.so.0') then      begin        SQLDBLibraryLoaderLinux.LibraryName := '/usr/lib/x86_64-linux- gnu/libsqlite3.so.0';        SQLDBLibraryLoaderLinux.Enabled := true;        SQLDBLibraryLoaderLinux.LoadLibrary;        // Set the filename of the sqlite database       SQLite3Connection1.DatabaseName := 'QuickHashDBLinux.sqlite';       // Create the database       CreateDatabase(SQLite3Connection1.DatabaseName);       if SQLIte3Connection1.Connected then lblConnectionStatus.Caption:= 'SQLite3 Database connection active';      end    // If it's 32-bit Linux, use the 32-bit SQLite3 install      else if FileExists('/usr/lib/i386-linux-gnu/libsqlite3.so.0') then        begin          SQLDBLibraryLoaderLinux.LibraryName := '/usr/lib/i386-linux-gnu/libsqlite3.so.0';          SQLDBLibraryLoaderLinux.Enabled := true;          SQLDBLibraryLoaderLinux.LoadLibrary;          // Set the filename of the sqlite database         SQLite3Connection1.DatabaseName := 'QuickHashDBLinux.sqlite';         // Create the database         CreateDatabase(SQLite3Connection1.DatabaseName);         if SQLIte3Connection1.Connected then lblConnectionStatus.Caption:= 'SQLite3 Database connection active';        end    else    begin    ShowMessage('Cannot create SQLite database. Ensure SQLite3 is installed in your Linux distribution');      exit;    end;    {$endif}{$endif}