Static linking SQLIte Linux lazarus / 16-Databases ---------------------------------------------------------------------- chrnobel · 2011-12-13 13:43 Hi all. I know this question have been raised before, but searching the forum didn't make me much wiser. The problem is straight forward - having an web application running on Linux as CGI, but not being certain that the SQLite library is there, and which version. I want to ensure that together with my project is also the SQLite library, typically in the same directory as the program. So does anyone have an easy to understand, step by step guide, showing how to do this in Lazarus? Thanks Christian ---------------------------------------------------------------------- jixian.yang · 2011-12-13 15:18 {$IFDEF FPC} {$MODE Delphi} {$ENDIF} interface uses {$IFDEF MSWINDOWS}   Windows,   Messages, {$ENDIF} {$IFDEF LINUX} // for Kylix   Libc,   Types, {$ENDIF}   Classes, {$IFDEF USETYPEINFO}   // this pure pascal version must handle the 64-bits ordinal values and   // the special layout of the underlying compiler (mostly FPC)   typinfo, {$ENDIF} {$IFNDEF LVCL}   Contnrs, // for TObjectList {$ENDIF}   SysUtils; {$IFNDEF FPC} {$L 'OBJ\sqlite3se.obj'}  //for Delphi {$ELSE} {$IFDEF MSWINDOWS} {$linklib libsqlite3se.a} {$linklib libmsvcrt.a} {$linklib libkernel32.a} {$linklib libgcc.a} {$ELSE} {$linklib libsqlite3selinux.a} {$Linklib c} {$linklib libgcc.a} {$ENDIF} {$ENDIF} and add -Xt in fpc.cfg. ---------------------------------------------------------------------- chrnobel · 2012-01-06 08:56 Sorry, might be that I am dumb -  but that did not make much sense, nor did it make me any wiser. I can get SQLite to work by copying these files to /usr/lib : libsqlite3.so (the library) libsqlite3.so.0 (link) libsqlite3.so.0.8.6 (link) The solution is 100% Linux only, and no Delphi etc. So how do I point to the library (which is in same directory as the binary) in FPC/Laz? ---------------------------------------------------------------------- BigChimp · 2012-01-06 09:11 Quote from: chrnobel on December 13, 2011, 02:43:22 pmI want to ensure that together with my project is also the SQLite library, typically in the same directory as the program. Instead of trying to get Linux to work like Windows (having the dll in your application directory) why not make sure the sqlite libraries are installed in their proper place? Then you wouldn't need to statically link to sqlite, the sqlite libraries get updated with the rest of the system etc I'd create a package for your distribution's package manager that does that for you... you could e.g. create a .deb file on Debian/Ubuntu or an .rpm on Redhat etc that contains your CGI application and a requirement that the sqlite package be installed... (Example: the libsqlite3-0 package on my Debian Squeeze x64 provides /usr/lib/libsqlite3.so.0 (symlink) and libsqlite3.so.0.8.6) If you don't want to use the package manager, I believe there are some "universal" Linux installers around, haven't worked with them, though... Quote from: chrnobelSo how do I point to the library (which is in same directory as the binary) in FPC/Laz? Are you saying your program is in /usr/lib, too? That would be a bit unusual? I haven't used sqlite in FPC on Linux yet, and can't tell you how that should work, but surely there's a wiki page on SQLite that should have that info? ---------------------------------------------------------------------- ludob · 2012-01-06 09:22 QuoteSo how do I point to the library (which is in same directory as the binary) in FPC/Laz? You can add directories to the library search path by setting the LD_LIBRARY_PATH environment variable. To add your current directory to the search path do Code: [Select]export LD_LIBRARY_PATH=. or Code: [Select]export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ---------------------------------------------------------------------- chrnobel · 2012-01-06 09:27 Quote from: BigChimp on January 06, 2012, 10:11:53 amInstead of trying to get Linux to work like Windows (having the dll in your application directory) why not make sure the sqlite libraries are installed in their proper place? Then you wouldn't need to statically link to sqlite, the sqlite libraries get updated with the rest of the system etc I can write a program in FPC that can be used on all most any distro, and if I can make a totally self contained product, by going "the Windows way", then the user can just run the program in userspace, and do not have to do any further installation - just like e.g. Firefox does. QuoteAre you saying your program is in /usr/lib, too? That would be a bit unusual?No on the contrary, the program shall run only in userspace, and without any requirement for acting as root, it was just to explain which files I am looking at. ---------------------------------------------------------------------- chrnobel · 2012-01-06 09:31 Quote from: ludob on January 06, 2012, 10:22:36 amQuoteSo how do I point to the library (which is in same directory as the binary) in FPC/Laz? You can add directories to the library search path by setting the LD_LIBRARY_PATH environment variable. To add your current directory to the search path do Code: [Select]export LD_LIBRARY_PATH=. or Code: [Select]export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATHCan this be done from inside the application - as mentioned I want to be able to handout a program, and no matter where the user copy this program (of course including the required libraries) he can use it without any further configuration/installation? ---------------------------------------------------------------------- ludob · 2012-01-06 09:52 QuoteCan this be done from inside the application - as mentioned I want to be able to handout a program, and no matter where the user copy this program (of course including the required libraries) he can use it without any further configuration/installation?If you are using a TSQLite3Connection you can set the full library path before it gets loaded. fe: Code: [Select]SQLiteLibraryName:='./sqlite3.so';To be done before any connection is established, fe. in an initialization section. ---------------------------------------------------------------------- chrnobel · 2012-01-06 12:19 Quote from: ludob on January 06, 2012, 10:52:53 amQuoteCan this be done from inside the application - as mentioned I want to be able to handout a program, and no matter where the user copy this program (of course including the required libraries) he can use it without any further configuration/installation?If you are using a TSQLite3Connection you can set the full library path before it gets loaded. fe: Code: [Select]SQLiteLibraryName:='./sqlite3.so';To be done before any connection is established, fe. in an initialization section. ludob you made my day - thanks :-)) I have for so long time tried to find a way, and then it can be done so simple - i really don't understand why such a simple and elegant solution is overlooked, and done into rocket science. So I ended up in this solution: Code: [Select]procedure TForm1.setparms(Sender: TObject); begin   SQLiteLibraryName:='./libsqlite3.so';   SQLite3Connection1.DatabaseName:='./test1.sqlite' ;   SQLite3Connection1.Connected:=true;   SQLTransaction1.Active:=true;   SQLQuery1.Active:=true;; end; The procedure is called when the form loads, and one shall ensure that the SQLite3Connection.connected is set to false in the IDE. ---------------------------------------------------------------------- BigChimp · 2012-01-06 13:06 Chrnobel, QuoteI have for so long time tried to find a way, and then it can be done so simple - i really don't understand why such a simple and elegant solution is overlooked, and done into rocket science. It does help if you provide a correct topic title and a bit more background information. I was confused by your post as I thought you wanted static linking. You didn't, you wanted to specify the path for a dynamic library. The first responder, understandably, responded to the static linking part. Fortunately, the next couple of posts clarified the situation so that Ludo could give you the non-rocket-science solution. In future, I would gently suggest that you provide a bit more information (what are you trying to do conceptually, what you tried) up front, be as clear as possible - not everybody understands the same level of English - and be a bit more forgiving yourself (saw the "elitist" remark on the future of Lazarus thread)... after all, we're trying to help here  That said, I had a quick look through the wiki and saw the sqlite documentation seems to be a bit of a mess. I also don't think the FPC documentation covers sqlite, so I understand your frustration. Regards, BigChimp Edit: added SQLiteLibraryName to wiki, not in an ideal spot, but this hopefully helps people: http://wiki.lazarus.freepascal.org/Lazarus_Dat abase_Tutorial#Using_the_SQLdb_components_with_TSQLIte3Connection ---------------------------------------------------------------------- chrnobel · 2012-01-06 13:36 Hi BigChimp I acknowledge that maybe I have misunderstood the Static Linking concept, but I would mean that this question quite clearly explains my problem: QuoteThe problem is straight forward - having an web application running on Linux as CGI, but not being certain that the SQLite library is there, and which version. I want to ensure that together with my project is also the SQLite library, typically in the same directory as the program.And I have asked the same question earlier where the topic was something like "SQLite (or was it MySQL) with embedded libfile" (can't quite remember  but it was something like that) - so it is actually quite difficult to make a topic in one line covering the whole problem, and I still consider it much better than just "SQLite3 problem". And don't get me wrong, I do so definitely appreciate the help given here, but we all have to sometimes understand that not all do have the same skill level, and if we want Lazarus to be a success,  everybody (including me self) have to be a bit humble. And the elitist remark is not targeted you, but we have to admit that some of the answers given (sometimes) to newbees are so rude that they can scare people away, which is a shame for both parts. BTW, thanks for the addition to the wiki, thumbs up :-)) /Christian ---------------------------------------------------------------------- BigChimp · 2012-01-06 14:08 Quote from: chrnobel on January 06, 2012, 02:36:27 pmAnd don't get me wrong, I do so definitely appreciate the help given here, but we all have to sometimes understand that not all do have the same skill level, and if we want Lazarus to be a success,  everybody (including me self) have to be a bit humble. And the elitist remark is not targeted you, but we have to admit that some of the answers given (sometimes) to newbees are so rude that they can scare people away, which is a shame for both parts. BTW, thanks for the addition to the wiki, thumbs up :-)) /Christian Christian, Thanks for clarifying & the thanks  Ok, all good  - on to the next problem and hopefully solution