天嵌 ARM开发社区

 找回密码
 注册
查看: 7739|回复: 22

EABI-4.3.3_EmbedSky_20091210编译器有问题啊!!!

[复制链接]
wanggewhut 发表于 2010-3-7 14:11:31 | 显示全部楼层 |阅读模式
本人的开发环境是:fedora10+EABI-4.3.3_EmbedSky_20091210+qtopia2.2,完全按照手册上的步骤搭建的。
而且在此平台上用qtopia2.2编写了一个串口界面,成功了。
接下来想在调试通过的程序基础上添加sqlite3数据库来记录串口受到的数据,但是按照《linux移植step by step》中的附录3“嵌入是数据库移植”进行了./bulid。
然后添加了sqlite3.h头文件到工程目录中(也是first.cpp等程序所在的文件夹),还在主文件first.cpp中也添加了extern "C" {#include <sqlite3.h>};
而且也“source setARM_QpeEnv”了。
但是,make不通过,报错如下:
[root@EmbedSky first_1.3new]# make
arm-linux-g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/include -o first.o first.cpp
arm-linux-g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/include -o main.o main.cpp
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/bin/moc first.h -o moc_first.cpp
arm-linux-g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/include -o moc_first.o moc_first.cpp
arm-linux-gcc  -o /opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/image/opt/Qtopia/bin/first first.o main.o  moc_first.o  -L/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/lib -L/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/lib -lm -lqpe -lqtopia -lqte
first.o: In function `first::my_openD()':
first.cpp:(.text+0x1c): undefined reference to `sqlite3_open'
first.cpp:(.text+0x48): undefined reference to `sqlite3_exec'
first.cpp:(.text+0x58): undefined reference to `sqlite3_free'
first.cpp:(.text+0x134): undefined reference to `sqlite3_close'
first.o: In function `first::my_closeD()':
first.cpp:(.text+0x16c): undefined reference to `sqlite3_close'
first.o: In function `first::handle_data_serial()':
first.cpp:(.text+0x31c): undefined reference to `sqlite3_exec'
collect2: ld returned 1 exit status
make: *** [/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/image/opt/Qtopia/bin/first] Error 1

即编译时找不到我在程序中用到的sqlite3_的open函数,close函数。。。
《linux移植step by step》的附录“3.2.3 使用slite”中不是说
“把 include 目录下文件拷贝到交叉编译器的 include 目录下,把 lib 目录下的库文件拷贝到交叉编译器的 lib 目录下,就让交叉编译器支持了 sqlite3 数据库了(我们提供的交叉编译器已经添加了对应的文件!!!!)”,那为什么还不识别sqlite3的函数呢??难道是EABI-4.3.3编译器不支持sqlite3???!我查看过sqlite3.h文件,其中有我用到的sqlite3_open等函数的定义啊!
该怎么办呢?

ps:附上first.cpp中和sqlite3相关的我写的代码段:

extern "C" {#include <sqlite3.h>};
/********************define the fd,buf********************/

static int fd,fd_beep,fd_sql;
static char my_buff[512];
char * errMsg = NULL;
sqlite3 *db;


void first::my_openD()
{
   // qWarning( "first::my_openD(): Not implemented yet!" );

struct termios newtio,oldtio;

/**************sqlite3 part****************/

fd_sql=::sqlite3_open("zigbeeData.db", &db);

if(fd_sql!=SQLITE_OK)
{
        ::sqlite3_close(db);
}

fd_sql=::sqlite3_exec(db, "CREATE TABLE Warn_TMP(SensorNO CHAR(32),TMP VARCHAR(32))", 0, 0, &errMsg);
        if(fd_sql!=SQLITE_OK)
{
        ::sqlite3_free(errMsg);
}       

/**************serial part****************/
 楼主| wanggewhut 发表于 2010-3-7 14:16:47 | 显示全部楼层
自己顶,希望版主今晚能看到啊!!!
 楼主| wanggewhut 发表于 2010-3-7 14:18:43 | 显示全部楼层
自己顶,希望版主今晚能看到啊!!!
fuzhuo20 发表于 2010-3-7 14:31:38 | 显示全部楼层
本帖最后由 fuzhuo20 于 2010-3-7 14:33 编辑

楼主的问题是没有指定连接到sqlite3的库文件
所以找不到具体函数实现的文件
解决方法
在.pro文件中应该加入
LIBS +=-lsqlite3
再重新tmake生成Makefile
再make
或者在Makefile文件中的
LIBS=
的内容后面加入 -lsqlite3

还有sqlite3.h及.so文件要放至编译环境目录
或在LD_LIBRARY_PATH中加入sqlite3所在目录
亚瑟王 发表于 2010-3-8 13:56:14 | 显示全部楼层
数据库的库文件和头文件在天嵌科技提供的4.3.3的编译器中已经存在了,而根据你提供的信息,你在链接时根本没有调用数据库的库文件,当然会出现找不到数据库中使用的函数了。
 楼主| wanggewhut 发表于 2010-3-11 15:31:03 | 显示全部楼层
感谢 fuzhuo20 兄的回复,正如所言,在工程中的makefile中,添加了LIBS +=-lsqlite3之后,含有sqlite3函数的代码编译获得通过,经试验发现能够sqlite3_open,sqlite3_exec...
而且也获得了程序执行后生成的.db文件(sqlite3的数据库数据文件),

但是在使用了sprintf函数(用于格式化欲插入数据库中已建成的表的数据)后,程序执行时发生报错“XXX was terminated due to application error(11)”,

百度该错误发现解决办法是“要添加头文件fcntl.h”和“close函数前面要加::(作用域符号)”,但该头文件我已经添加过了,“::”我也是每个函数都加了的。这该怎么办呢??
 楼主| wanggewhut 发表于 2010-3-11 15:40:28 | 显示全部楼层
我想知道的是:天嵌的EABI-4.3.3编译器支持sprintf函数吗?我编译含有sprintf函数是没有报错可以通过的,就是一运行程序就弹“XXX was terminated due to application error(11)”对话框!而且生成的数据库文件(.db文件)是空的,只建立了表项,而没有能够插入数据。

与之前代码的区别是添加了如下部分:
/*************define area*****************/
static char buff_mid[100]="HELLO!";

char * errMsg = NULL;
char * sql_CMD = NULL;

sqlite3 *db;

/**************sqlite3 part****************/
......
......
::sprintf(sql_CMD,"INSERT INTO Warn_TMP VALUES ('%s')",buff_mid);
::sqlite3_exec(db,sql_CMD,0,0,$errMsg);
亚瑟王 发表于 2010-3-11 16:10:00 | 显示全部楼层
sprintf函数需要重新实现哦,我还没有发现编译器自带了这个函数的。编译uboot时,使用的这个函数就是自己实现的。
 楼主| wanggewhut 发表于 2010-3-12 10:42:39 | 显示全部楼层
杯具啊,内牛满面啊
亚瑟王 发表于 2010-3-12 14:30:40 | 显示全部楼层
我从2.9.25到目前的4.3.3的编译器都没有在编译器里面发现过支持sprintf。
 楼主| wanggewhut 发表于 2010-3-12 16:39:32 | 显示全部楼层
版主,俺身边有同学用的QQ2440的板子,编译器是3.4.1的。他移植了sqlite3.6.X,并在程序中用到了sprintf函数如下:“sprintf(qry,"INSERT INTO \"user\" (username,password)\n" "VALUES ('%s','%s')", postvars[1],postvars[3]);”他的程序是可以正常运行的啊。

我从网上下载了一个sprintf.cpp文件(该文件号称“sprintf源码。独立一个文件就可用。在嵌入式等系统中可能用到。网上找了很多,多数都不能用或功能不全。这个是本人下了一翻功夫完善过的代码”),添加到$QTDIR/include文件夹下了。同时在我的主文件first.cpp中添加了:
/*************define area*****************/
#include <sprintf.cpp>

static char buff_mid[100]="HELLO!";

char * errMsg = NULL;
char * sql_CMD = NULL;

sqlite3 *db;

/**************sqlite3 part****************/
int sprintf(char *buf, const char *fmt, ...);//这是函数sprintf的声明
                                           //是直接从sprintf.cpp文件中copy过来的
......
......
::sprintf(sql_CMD,"INSERT INTO Warn_TMP VALUES ('%s')",buff_mid);
::sqlite3_exec(db,sql_CMD,0,0,$errMsg);

但是编译通不过啊!!
 楼主| wanggewhut 发表于 2010-3-12 16:49:29 | 显示全部楼层
以下是编译的报错信息:
[root@EmbedSky first_1.3new]# make
arm-linux-g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include -I/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qtopia/include -o first.o first.cpp
In file included from first.cpp:35:
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:23: error: conflicting declaration 'typedef char* va_list'
/opt/EmbedSky/4.3.3/bin/../arm-none-linux-gnueabi/libc/usr/include/stdio.h:80: error: 'va_list' has a previous declaration as 'typedef struct __gnuc_va_list va_list'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:57: warning: deprecated conversion from string constant to 'char*'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:58: warning: deprecated conversion from string constant to 'char*'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp: In function 'long unsigned int my_strnlen(const char*, int)':
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:151: warning: suggest a space before ';' or explicit braces around empty body in 'for' statement
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp: At global scope:
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:274: warning: unused parameter 'precision'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:302: warning: unused parameter 'precision'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp: In function 'char* ecvtbuf(double, int, int*, int*, char*)':
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:554: warning: suggest a space before ';' or explicit braces around empty body in 'while' statement
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp: In function 'void cfltcvt(double, char*, char, int)':
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:641: warning: unused variable 'digits'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp: In function 'void cropzeros(char*)':
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:773: warning: suggest parentheses around assignment used as truth value
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:773: warning: suggest a space before ';' or explicit braces around empty body in 'while' statement
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp: In function 'int my_vsprintf(char*, const char*, va_list)':
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:944: warning: deprecated conversion from string constant to 'char*'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:1048: warning: 'short int' is promoted to 'int' when passed through '...'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:1048: note: (so you should pass 'int' not 'short int' to 'va_arg')
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:1048: note: if this code is reached, the program will abort
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:1050: warning: 'short unsigned int' is promoted to 'int' when passed through '...'
/opt/EmbedSky/Qte/arm-qtopia-2.2.0/qt2/include/sprintf.cpp:1050: note: if this code is reached, the program will abort
make: *** [first.o] Error 1
 楼主| wanggewhut 发表于 2010-3-12 16:55:54 | 显示全部楼层
我现在困在sprintf函数的使用上了!!!
在我写的程序中,从串口读到的数据存在了一个char buff[64]中,但是要想把该数组中的串口数据存到sqlite3嵌入式数据库中去,就必须把buff[]中的串口数据按照sqlite数据库要求的格式弄好,这个工作就是用sprintf函数来完成的---sprintf(sql_CMD,"INSERT INTO Warn_TMP VALUES ('%s')",buff);如果sprintf函数不能用,那怎么样才能把数组buff中存的数据insert into到数据库中去呢??!
 楼主| wanggewhut 发表于 2010-3-12 20:26:41 | 显示全部楼层
俺找到了同学的那个编译器,是arm-linux-gcc-4.3.2.tgz的,版本比天嵌的4.3.3的要低。如果用这个编译器编译我写的程序,是不是不能在文件系统里使用生成的可执行文件啊?唉,晕死了!!
能不能把4.3.2编译器里与sprintf函数相关的头文件,库文件都提出来添加进天嵌的4.3.3的编译器中去啊?该怎么做呢??!
 楼主| wanggewhut 发表于 2010-3-12 20:56:26 | 显示全部楼层
http://blog.csdn.net/s0805341/archive/2009/10/16/4681251.aspx
这个网页上就有用sprintf函数的地方:

char buf[256];   
char *v1="你好";   
sprintf(buf,"insert into \"gpio_config_info\" values('%s');",v1);   
sql=buf;   
sqlite3_exec(db,sql,0,0,&zErrMsg);
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-28 03:26 , Processed in 1.030313 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表