040——移植数据库sqlite3到i.mx6ull

目录

一、下载

二、移植数据库

三、测试sqlite3


一、下载

SQLite Download Page

暂时先下载最新版的试试,我们以前其实在ubuntu上直接使用过

嵌入式数据库sqlite3_常见的嵌入式数据库-CSDN博客

当时我把常用的操作和怎么使用记录下来了

现在把他移植到开发板上看看行不行

二、移植数据库

        喵的这下载是真的慢呀,下了一天,挂个梯子好了。不对与其自我反思不如批判别人。中国14亿人,为啥不给搞个服务器哇。(手动狗头)

先解压看看

最上层的这些貌似是配置咋编译的我研究一下

下面这介个makefile应该是根据不同的平台来指定的。

我觉得第一步应该是执行这个config脚本来配置makefile一般来说都是这个套路

服了,文档也没说给个使用说明。

抱歉我错怪他了,原来有readme

This package contains:

 * the SQLite library amalgamation source code file: sqlite3.c
 * the sqlite3.h and sqlite3ext.h header files that define the C-language
   interface to the sqlite3.c library file
 * the shell.c file used to build the sqlite3 command-line shell program
 * autoconf/automake installation infrastucture for building on POSIX
   compliant systems
 * a Makefile.msc, sqlite3.rc, and Replace.cs for building with Microsoft
   Visual C++ on Windows

SUMMARY OF HOW TO BUILD
=======================

  Unix:      ./configure; make
  Windows:   nmake /f Makefile.msc

BUILDING ON POSIX
=================

The generic installation instructions for autoconf/automake are found
in the INSTALL file.

The following SQLite specific boolean options are supported:

  --enable-readline           use readline in shell tool   [default=yes]
  --enable-threadsafe         build a thread-safe library  [default=yes]
  --enable-dynamic-extensions support loadable extensions  [default=yes]

The default value for the CFLAGS variable (options passed to the C
compiler) includes debugging symbols in the build, resulting in larger
binaries than are necessary. Override it on the configure command
line like this:

  $ CFLAGS="-Os" ./configure

to produce a smaller installation footprint.

Other SQLite compilation parameters can also be set using CFLAGS. For
example:

  $ CFLAGS="-Os -DSQLITE_THREADSAFE=0" ./configure


BUILDING WITH MICROSOFT VISUAL C++
==================================

To compile for Windows using Microsoft Visual C++:

  $ nmake /f Makefile.msc

Using Microsoft Visual C++ 2005 (or later) is recommended.  Several Windows
platform variants may be built by adding additional macros to the NMAKE
command line.

Building for WinRT 8.0
----------------------

  FOR_WINRT=1

Using Microsoft Visual C++ 2012 (or later) is required.  When using the
above, something like the following macro will need to be added to the
NMAKE command line as well:

  "NSDKLIBPATH=%WindowsSdkDir%\..\8.0\lib\win8\um\x86"

Building for WinRT 8.1
----------------------

  FOR_WINRT=1

Using Microsoft Visual C++ 2013 (or later) is required.  When using the
above, something like the following macro will need to be added to the
NMAKE command line as well:

  "NSDKLIBPATH=%WindowsSdkDir%\..\8.1\lib\winv6.3\um\x86"

Building for UWP 10.0
---------------------

  FOR_WINRT=1 FOR_UWP=1

Using Microsoft Visual C++ 2015 (or later) is required.  When using the
above, something like the following macros will need to be added to the
NMAKE command line as well:

  "NSDKLIBPATH=%WindowsSdkDir%\..\10\lib\10.0.10586.0\um\x86"
  "PSDKLIBPATH=%WindowsSdkDir%\..\10\lib\10.0.10586.0\um\x86"
  "NUCRTLIBPATH=%UniversalCRTSdkDir%\..\10\lib\10.0.10586.0\ucrt\x86"

Building for the Windows 10 SDK
-------------------------------

  FOR_WIN10=1

Using Microsoft Visual C++ 2015 (or later) is required.  When using the
above, no other macros should be needed on the NMAKE command line.

Other preprocessor defines
--------------------------

Additionally, preprocessor defines may be specified by using the OPTS macro
on the NMAKE command line.  However, not all possible preprocessor defines
may be specified in this manner as some require the amalgamation to be built
with them enabled (see http://www.sqlite.org/compile.html). For example, the
following will work:

  "OPTS=-DSQLITE_ENABLE_STAT4=1 -DSQLITE_OMIT_JSON=1"

However, the following will not compile unless the amalgamation was built
with it enabled:

  "OPTS=-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT=1"

        上来就说了先config在make好好好

        我估计还得有指定编译器和目标目录的选项之前移植boa和jpeg的时候就是这种步骤。

./configure CC=arm-buildroot-linux-gnueabihf-gcc --host=arm-buildroot-linux-gnueabihf --prefix=../

不出意外的报错了

看样子不能写相对路径

哦吼果然是这个样子

makefile也出来了现在我们make试试

卡在这了不知道是编译的太慢了还是出错了

看样子是编译的太慢了。问题不大

然后make install就可以把库文件移动到刚刚指定的目录了

有点大哇就不放到我的项目里了

这个可执行文件应该是可以配合其它的描述文件进行sql的shell操作

把东西放到板子上看看

可执行文件放到bin下,其他的lib下的动态库放lib

然后忘了这个了刚刚查了一下这个是帮助链接的文件

pkg-config 是一个在 Unix-like 系统(如 Linux)中用于帮助编译器和链接器找到并使用已安装的库的工具。pkg-config 通过读取特定的 .pc(Package Config)文件来提供库的各种必要信息,如版本信息、编译和连接需要的参数等。

以下是 pkg-config 的一些主要功能和作用:

  1. 检查库的版本号pkg-config 可以检查所需库的版本是否满足要求,如果版本不满足,它会打印出错误信息,避免连接到错误版本的库文件。
  2. 获得编译预处理参数:例如宏定义和头文件的路径。这对于编译器在编译时找到正确的头文件非常重要。
  3. 获得编译参数:如库及其依赖的其他库的位置、文件名以及其他一些连接参数。这对于链接器在链接时找到正确的库文件非常重要。
  4. 自动加入所依赖的其他库的设置:当一个库依赖于其他库时,pkg-config 可以自动将这些依赖项添加到编译和链接命令中。
  5. 解决编译连接界面不统一问题:由于库文件可能安装在不同的目录下,使用 -I 和 -L 参数手动指定头文件和库文件的路径可能会导致编译命令界面的不统一。pkg-config 通过预定义的 .pc 文件来提供这些信息,从而解决了这个问题。
  6. 简化编译和链接:通过自动提供正确的编译和链接选项,pkg-config 减少了手动管理这些选项的复杂性。
  7. 便于自动化:在构建系统和脚本中,pkg-config 可以自动化地解决依赖问题,无需人工干预。

在使用 pkg-config 时,通常会通过命令行参数(如 --cflags 和 --libs)来指定需要提取的信息类型。例如,pkg-config --cflags --libs libname 命令会输出与 libname 库相关的编译和链接选项。

虽然我们交叉编译,但是在板子上也放一个好了

还有一个是share下面有个man文件看样子是用来更新man手册的

齐活了

三、测试sqlite3

ok呀,shell模式可以用了太久没用忘了咋用了哈哈

嵌入式数据库sqlite3-CSDN博客

还好以前记录的笔记还算全

下面写个测试程序看看能不能用api

先修改编译框架

不认识这些api呢

明明有哇

没链接库

没毛病

/*  
 * File name : sql.c
 * Function  : sql handle
 * Date      : 2024-05-12  
 * Version   : 0.1.0  
 */
/************************************************************************************
***************************************INCLUDE***************************************
*************************************************************************************/
#include "sql.h"
/************************************************************************************
***************************************EXTERN****************************************
*************************************************************************************/
 
int callback(void *arg, int f_num, char ** f_value, char ** f_name)
{
	int i = 0;
 
	for(i = 0; i < f_num; i++)
	{
	//	printf("%-8s %s", f_value[i], f_name[i]);
		printf("%-8s", f_value[i]);
	}
 
	printf("++++++++++++++++++++++");
	putchar(10);
 
	return 0;
}
 
int sql_test()
{
	sqlite3 *db;
	char *errmsg;//errmsg是一个二级指针,定义一个一级指针取地址。
	char sql[128];
	if(sqlite3_open(DATABASE, &db) != SQLITE_OK)
	{
		printf("%s\n", sqlite3_errmsg(db));
		return -1;
	}
	else
	{
		printf("open DATABASE success.\n");
	}
 
	if(sqlite3_exec(db, "create table if not exists xty(id int, device char , data char);",NULL, NULL, &errmsg) != SQLITE_OK)//分号可加可不加
	{
		printf("%s\n", errmsg);
	}
	else
	{
		printf("Create or open table success.\n");
	}
	sprintf(sql, "insert into xty values(%d, '%s', '%s')", 1, "gps", "001");
 
	if(sqlite3_exec(db, sql, NULL, NULL, &errmsg) != SQLITE_OK)
	{
		printf("%s\n", errmsg);
	}
	else
	{
		printf("Insert done.\n");
	}
    sprintf(sql, "select count(*) from xty where name='gps';");
	if(sqlite3_exec(db, sql, callback,NULL , &errmsg) != SQLITE_OK)
	{
		printf("%s", errmsg);
	}
	else
	{
		printf("select done.\n");
	}
	return 0;
}
 

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇努力学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值