How to compile SQLite embedded databases in arm-Linux

Source: Internet
Author: User
How to compile SQLite embedded databases in arm-Linux

Step 1SQLiteCompilation in arm-Linux
1. Download SQLite: Go to ghost.

2. Make sure that your path contains the cross-compilation tool arm-Linux-GCC. You can run the "Echo $ path" command to view details. For example, "/opt/toolchain/GCC 3.2/toolchain/bin /"

3. To run SQLite properly in arm-Linux, we need to modify a code. OtherwiseArmWhen running SQLite on the Board, the following things will appear:
====================================
An assertion is thrown in file btree. C,
Assert (sizeof (PTR) = sizeof (char *));
====================================
This assertion is to ensure that btree (B-tree) has the correct variable size, such as "PTR" and "char *". In different architecturesLinuxSuch as x86 and arm. In the case of arm-Linux :-). So we can make some changes.
Modify SQLite/src/sqliteint. h and find the following parts:
# Ifndef intptr_type
# If sqlite_ptr_sz = 4
# Define intptr_type int
# Else
# Define intptr_type long
# Endif
Add the following sentence before the above Code:
# Define sqlite_ptr_sz 4
In this case, "typedef intptr_type PTR;" is the defined "int" type instead of "long ".

4. Use configure for configuration. Find the following four items in configure under the SQLite directory and comment them out, so that configure does not check your cross-compilation environment. Note: Make sure that your "arm-Linux-" commands are in your path environment variables. For example, you can enter "arm-Linux-" and press "tab" to check whether the command line is automatically completed.
# If test "$ cross_compiling" = "yes"; then
# {Echo "$ as_me: 12710: Error: unable to find a compiler for building build tools"> & 5
# Echo "$ as_me: Error: unable to find a compiler for building build tools"> & 2 ;}
# {(Exit 1); Exit 1 ;};}
# Fi
...
# Else
# Test "$ cross_compiling" = Yes &&
# {Echo "$ as_me: 13264: Error: cannot check for file existence when cross compiling"> & 5
# Echo "$ as_me: Error: cannot check for file existence when cross compiling"> & 2 ;}
# {(Exit 1); Exit 1 ;};}
...
# Else
# Test "$ cross_compiling" = Yes &&
# {Echo "$ as_me: 13464: Error: cannot check for file existence when cross compiling"> & 5
# Echo "$ as_me: Error: cannot check for file existence when cross compiling"> & 2 ;}
# {(Exit 1); Exit 1 ;};}
...
# Else
# Test "$ cross_compiling" = Yes &&
# {Echo "$ as_me: 13490: Error: cannot check for file existence when cross compiling"> & 5
# Echo "$ as_me: Error: cannot check for file existence when cross compiling"> & 2 ;}
# {(Exit 1); Exit 1 ;};}
After being commented out, You can execute configure. In the SQLite-arm-Linux directory, enter the following command:
../SQLite/configure -- Host = arm-Linux
In this way, the makefile and libtool script will be generated in your build directory, which will be used in make.

5. Modify the MAKEFILE file
Modify the MAKEFILE file.
BCC = arm-Linux-gcc-g-O2
Change:
BCC = gcc-g-O2

Generally, SQLite is run on an arm-Linux hardware board, so we generally compile it into a static link. It is troublesome to share the so library.
So continue to modify the makefile and find the following:
SQLite:
Replace "libsqlite. La"
". Libs/libsqlite."
Now you can make it.
There should be no error. Generate SQLite, libsqlite. A, libsqlite. So. You can run the find-name "SQLite"; find-name "*. A"; find-name "*. So" command to view the directory where the file is located.
The generated SQLite file has not been strip yet. You can run the "file SQLite" command to view the file information. After processing with strip, the debugging information will be removed, and the execution file size will be much smaller. The command is as follows:
Arm-Linux-strip SQLite

Step 2 run SQLite on the arm Board
You can copy SQLite to your arm board in many ways. For example, FTP, FTP, and wget.
My method is to use wget to download SQLite to the/tmp directory of the arm board, which is writable. The command is as follows:
Busybox wgetftp: // 192.168.0.100/SQLite
The above command shows that busybox is already on my board to support the wget command. :-)
OK, start running
Chmod + wx SQLite
./SQLite test. SQLite
Will appear
SQLite>
Prompt symbol. Click ". Help" to see the command :-)
SQLite>. Help
Okay. Now SQLite is running in arm-Linux. How can this problem be solved? Play the select * From Statement on the arm board :-)

Tip:
If SQLite Encounters "the database disk image is malformed" during database processing, for example, you may encounter this problem when deleting from sometable.
In this case, your arm Board does not have enough space (for example, under/tmp). delete some files. I encountered this prompt when I had 1 to 2 MB space left. After deletion, 4 MB is left blank, and the operation is normal (for example, delete from sometable ). I am opening an 8 m ramdisk for development :-)

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.