How to static linking SQLite library? lazarus / 16-Databases ---------------------------------------------------------------------- luigi65 · 2008-11-16 15:32 I've written an application which uses sqlite and thus far it works fine as long as I compile it linking to the library dynamically (the shared library is present on /usr/lib). However, I would like to be able to distribute this application to people who do not necessarily have the sqlite libraries installed, and so I want to link the sqlite libraries statically. How can do it with lazarus 0.9.26 on Linux Fedora 9? Thanks and goodbye ---------------------------------------------------------------------- Leledumbo · 2008-11-17 03:20 Add -XS compiler option ---------------------------------------------------------------------- luigi65 · 2008-11-17 14:02 I have added this option on file /etc/fpc.cfg, but this don't work. The application functions only if  there is the shared library on /usr/lib/libsqlite.so. ---------------------------------------------------------------------- Leledumbo · 2008-11-18 04:44 Sorry, I mean -Xt. ---------------------------------------------------------------------- luigi65 · 2008-11-18 18:47 Excuse me, but where do I set this option? If I set in the IDE on Compiler Options->Linking->Options (-k) with "Pass Options To The Linker" active, I obtain the error: "/usr/bin/ld: unrecognized option -Xt". If I set in /etc/fpc.cfg, I obtain the error: "/usr/bin/ld: cannot find -lX11". But I can to compile without this option, also libX11, libX11-devel, etc. are installed. Can you help me? ---------------------------------------------------------------------- Phil · 2008-11-18 19:07 Quote from: "luigi65"Excuse me, but where do I set this option? If I set in the IDE on Compiler Options->Linking->Options (-k) with "Pass Options To The Linker" active, I obtain the error: "/usr/bin/ld: unrecognized option -Xt". If I set in /etc/fpc.cfg, I obtain the error: "/usr/bin/ld: cannot find -lX11". But I can to compile without this option, also libX11, libX11-devel, etc. are installed. Can you help me? That's an FPC compiler switch, not a linker switch, so enter it on the Other tab. From what the FPC help says, adding the -Xt switch causes it to pass -static to the linker. Thanks. -Phil ---------------------------------------------------------------------- luigi65 · 2008-11-19 08:55 I have set the option -Xt in /etc/fpc.cfg, but now I obtain the error: "/usr/bin/ld: cannot find -lX11". But the libraries libX11, libX11-devel, etc. are installed. If I compile the application without that option then all is ok, but naturally the library is not static linked. There's another place where can I set the option -Xt? Thank you for your answers ---------------------------------------------------------------------- Leledumbo · 2008-11-19 09:56 That's weird, try -k-static. If the problem persists, I guess the linker also expects static library of X11 which is not found since AFAIK only the shared objects are installed. ---------------------------------------------------------------------- luigi65 · 2008-11-21 09:24 Whether I set -Xt, whether I set -k -static I always obtain the error: "/usr/bin/ld: cannot find -lX11" On my Fedora 8 I have installed the libraries: libX11-1.1.3-4.fc8.i386 libX11-devel-1.1.3-4.fc8.i386 Perhaps the static version of X11 is not present on those libraries? I note that in /usr/lib there is libX11.so but anywhere I find libX11.a, the directory /usr/lib/X11 is empty. Where can I find the static version of X11? Thanks ---------------------------------------------------------------------- Leledumbo · 2008-11-21 12:09 QuoteWhere can I find the static version of X11? I don't think it's available anywhere. It seems unnatural to link X11 statically as your code would be bloated (several to hundred megs, perhaps?). According to ld manual: Quote -static     Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects library searching for -l options which follow it. This option also implies --unresolved-symbols=report-all. This option can be used with -shared. Doing so means that a shared library is being created but that all of the library's external references must be resolved by pulling in entries from static libraries. Use -Cn so that FPC generates linker script to compile your program, and edit the linker flags to only statically link sqlite. My suggestion: bundle libsqlite.so with your program, much easier than making it statically linked. It's not a heavy library, just a single .so. Why bother linking it statically? ---------------------------------------------------------------------- luigi65 · 2008-11-21 13:40 Sorry, but how do I do bundle libsqlite.so with my application? I have tried adding the path './' in Compiler Options->Libraries and moving the libsqlite.so (from /usr/lib/) in my application directory, but if I run my program I obtain an exception. How can I specify in Lazarus to use the libsqlite.so present on application directory? Thanks ---------------------------------------------------------------------- Leledumbo · 2008-11-24 03:11 QuoteSorry, but how do I do bundle libsqlite.so with my application? Deploying  Your Application QuoteI have tried adding the path './' in Compiler Options->Libraries and moving the libsqlite.so (from /usr/lib/) in my application directory, but if I run my program I obtain an exception. How can I specify in Lazarus to use the libsqlite.so present on application directory? On Unix, when you run a program from a directory (let's say ~/me), it doesn't always mean that it's the directory where the application runs (it can be /usr or anything else). Read Multiplatform Programming Guide for more info. ---------------------------------------------------------------------- LuizAmérico · 2008-11-29 14:35 Quote from: "luigi65"Sorry, but how do I do bundle libsqlite.so with my application? The so extension means shared object, similar to a windows dll. It's not possible to link such files. Is necessary to compile the sqlite source into a static object (has a .o extension) and then link using {$l} directive. It's not difficult but requires some knowledge. You can find that info in the net. The {$l} doc: http://www.freepascal.org/docs-html/prog/progsu41.html#x48-460001.1.41 ---------------------------------------------------------------------- luigi65 · 2008-12-02 09:28 In Windows version of my program I only have copied the sqlite3.dll on application directory, and this works fine. But in Lazarus (Linux) there's the possibilty to tell to compiler search the libsqlite.so on current directory (same of executable file) and not in/usr/lib/? ---------------------------------------------------------------------- Leledumbo · 2008-12-03 02:31 QuoteBut in Lazarus (Linux) there's the possibilty to tell to compiler search the libsqlite.so on current directory (same of executable file) and not in/usr/lib/? It's not related to Lazarus or FPC, it's the Linux structure that forces you to put it there. I don't know if manually loading the library (through LoadLibrary, get the relative location by using ParamStr(0)) can help or not, but it's worth to try. ---------------------------------------------------------------------- luigi65 · 2008-12-03 10:48 I try this code: Code: [Select]   hLibSql := LoadLibrary('/opt/lazarus/myapp/libsqlite3.so.0.8.6');   if hLibSql <> nilhandle then begin     ZConnection.Protocol := 'sqlite-3';     ZConnection.Catalog := '/opt/lazarus/myapp/';     ZConnection.Database := '/opt/lazarus/myapp/myDb.s3db';     ZConnection.Connected := True;   end; but in debug mode when I reach the row "ZConnection.Connected := True;" I get the error "Project myProj raised exception class 'Exception' with message: None of the dynamic libraries can be found: libsqlite.so". I also try rename libsqlite3.so.0.8.6 to libsqlite.so but I obtain the same error. Have you others suggestions? Thanks for your patience.