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.
Download test project
The following describes the methods.
1. Download the source code of SQLite.
(Correction: amalgamation is not all in one, but core code all in one. Other files in the source code are also indispensable !)
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, to use the sqlite3_open method Source code The statement is as follows:
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
Enjoy ~