Recent

Author Topic: How to static linking SQLite library?  (Read 23785 times)

luigi65

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
How to static linking SQLite library?
« on: November 16, 2008, 04:32:56 pm »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: How to static linking SQLite library?
« Reply #1 on: November 17, 2008, 04:20:22 am »
Add -XS compiler option

luigi65

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
RE: How to static linking SQLite library?
« Reply #2 on: November 17, 2008, 03:02:42 pm »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: How to static linking SQLite library?
« Reply #3 on: November 18, 2008, 05:44:06 am »
Sorry, I mean -Xt.

luigi65

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
How to static linking SQLite library?
« Reply #4 on: November 18, 2008, 07:47:13 pm »
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

  • Hero Member
  • *****
  • Posts: 2737
How to static linking SQLite library?
« Reply #5 on: November 18, 2008, 08:07:13 pm »
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

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
How to static linking SQLite library?
« Reply #6 on: November 19, 2008, 09:55:53 am »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
How to static linking SQLite library?
« Reply #7 on: November 19, 2008, 10:56:39 am »
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

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
How to static linking SQLite library?
« Reply #8 on: November 21, 2008, 10:24:46 am »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
How to static linking SQLite library?
« Reply #9 on: November 21, 2008, 01:09:36 pm »
Quote
Where 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

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
How to static linking SQLite library?
« Reply #10 on: November 21, 2008, 02:40:48 pm »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
How to static linking SQLite library?
« Reply #11 on: November 24, 2008, 04:11:26 am »
Quote
Sorry, but how do I do bundle libsqlite.so with my application?

Deploying  Your Application
Quote
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?

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

  • Sr. Member
  • ****
  • Posts: 457
How to static linking SQLite library?
« Reply #12 on: November 29, 2008, 03:35:13 pm »
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

  • New Member
  • *
  • Posts: 24
    • http://www.lodevelop.org
How to static linking SQLite library?
« Reply #13 on: December 02, 2008, 10:28:13 am »
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

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
How to static linking SQLite library?
« Reply #14 on: December 03, 2008, 03:31:05 am »
Quote
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/?

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.

 

TinyPortal © 2005-2018