) How to statically link SQLite in Delphi

Source: Internet
Author: User
Tags sqlite db
After several hours, I finally succeeded in Statically linking SQLite (v3.5.4) in Delphi. The next step is to study encryption.
In fact, I encountered a lot of problems in the middle. If I am tired today, I will not talk about it. I will try again in the next day.

1. Download SQLite Source code Haha, but remember to use the amalgamation version of all in one.
(Fixed: amalgamation is not all in one, but core code all in one. The Source Code Other files in !)
2. decompress the package and obtain the sqlite3.c sqlite3.h sqlite3ext. h file.
Then compile sqlite3.c into OBJ for use in Delphi
Note that do not use VC compilation. use Borland's c ++ compiler, such as the built-in BCC of Delphi.
This is mainly because the OBJ compiled by VC is in coff format, while the OBJ used by Borland is in OMF format.
Command Line compiled by BCC: bcc32-PC-RT--o-w--6-I (bcc32) \ include-C sqlite3.c
3. sqlite3.obj is not enough, because sqlite3.c has links to other libraries.
Download all OBJ files to be used
4. Now all the OBJ files are ready, but it's too early to be happy. Now it's only a small part...
To use these OBJ functions in Delphi, you must declare
Create a new unit, such as sqlite3.pas, and specify the OBJ file of the link, as shown in figure
{$ L 'obj \ sqlite3_5_4.obj '}
{$ L 'obj \ streams. OBJ '} // duplicato
{$ L 'obj \ _ ftoul. OBJ '}
{$ L 'obj \ files. OBJ '}
Pay attention to the order.
Then add the function declaration
For example, if you want to use the sqlite3_open method, declare it in the source code of SQLite.
Sqlite_api int sqlite3_open (
Const char * filename,/* database filename (UTF-8 )*/
Sqlite3 ** ppdb/* Out: SQLite dB handle */
);
In Delphi, the corresponding declaration is:
Function _ sqlite3_open (dbname: pchar; var DB: pointer): integer; cdecl; external;
Note that the call method is cdecl and the function name must start with _. Otherwise, the function cannot be found.
It's just a lot of sqlite3 functions...
5. OK. The function declaration is complete.
Now we can officially use it ~
FAQs:
1. Unsatisfied forward or external declaration during compilation
This error occurs because the declared function cannot be found.
Generally, it is because the linked OBJ file is incomplete or the order is incorrect.
The declared function name is incorrect and cannot be found.
2. Internal error: l3576 during compilation
Declared function parameters do not match

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.