Recent

Author Topic: How does FPC determine which SQLite shared library to link to on Linux?  (Read 346 times)

PierceNg

  • New Member
  • *
  • Posts: 31
I'm on Ubuntu and Alpine Linux. I'm using this SQLite binding:

  https://github.com/plashenkov/SQLite3-Delphi-FPC

Example program:

Code: Pascal  [Select][+][-]
  1. program dbtest;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   SQLite3Wrap;
  7.  
  8. const
  9.   DatabaseFileName = 'x.db';
  10.   Schema = 'create table if not exists x (' +
  11.     'id integer primary key, ' +
  12.     'x varchar' +
  13.     ')';
  14.   InsertSQL = 'insert into x values (NULL, ?)';
  15.  
  16. var
  17.   db: TSQLite3Database;
  18.   stmt: TSQLite3Statement;
  19.  
  20. begin
  21.   try
  22.     db := TSQLite3Database.create;
  23.     db.open(DatabaseFileName);
  24.  
  25.     db.beginTransaction;
  26.     db.execute(Schema);
  27.     db.commit;
  28.  
  29.     stmt := db.prepare(InsertSQL);
  30.     stmt.bindText(1, '42');
  31.     db.beginTransaction;
  32.     stmt.stepAndReset;
  33.     db.commit;
  34.   finally
  35.     stmt.free;
  36.     db.free;
  37.   end;
  38. end.
  39.  

The SQLite binding defines the following:

Code: Pascal  [Select][+][-]
  1. const
  2. {$IFDEF MSWINDOWS}
  3.   sqlite3_lib = 'sqlite3.dll';
  4. {$ENDIF}
  5. {$IFDEF UNIX}
  6.   sqlite3_lib = 'sqlite3.so';
  7. {$ENDIF}
  8. {$IFDEF DARWIN}
  9.   sqlite3_lib = 'libsqlite3.dylib';
  10. {$ENDIF}

All SQLite functions are declared in similar style:

Code: Pascal  [Select][+][-]
  1. function sqlite3_libversion: PAnsiChar; cdecl; external sqlite3_lib;

Compile my example program:

Code: Bash  [Select][+][-]
  1. % fpc dbtest.pas
  2. fpc dbtest.pas
  3. Free Pascal Compiler version 3.2.0 [2020/07/07] for x86_64
  4. Copyright (c) 1993-2020 by Florian Klaempfl and others
  5. Target OS: Linux for x86-64
  6. Compiling dbtest.pas
  7. Linking dbtest
  8. 42 lines compiled, 0.2 sec

By default the executable links to the system-provided SQLite shared library:

Code: Bash  [Select][+][-]
  1. % ldd dbtest
  2.         linux-vdso.so.1 (0x00007ffdad689000)
  3.         libsqlite3.so.0 => /lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007ff044862000)
  4.         libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff044713000)
  5.         libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff0446f0000)
  6.         libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff0446ea000)
  7.         libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff0444f8000)
  8.         /lib64/ld-linux-x86-64.so.2 (0x00007ff0449a4000)

How to tell FPC to link to my self-compiled libsqlite3.so? I want to use my own libsqlite3.so to make sure that the SQLite functionality my program uses is indeed in the shared library the program links to.



 

TinyPortal © 2005-2018