使用Sqlite出现undefined reference to `sqlite3_open'错误的解决
2008-08-30 17:13
603 查看
假设你已经正确编译和安装了Sqlite,写个测试程序来测试:
#include <stdlib.h>
#include <stdio.h>
#include "sqlite3.h"
int main(void)
{
sqlite3 *db=NULL;
char *zErrMsg = 0;
int rc;
rc=sqlite3_open("test1.db",&db);
if(rc)
{
fprintf(stderr,"Can't open database: %s\n",sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
else printf("open mydata successfully!\n");
sqlite3_close(db);
return 0;
}
用GCC来编译的时候总是会出现错误,编译的命令如下
gcc -static -o hello -lsqlite3 -L /usr/local/lib -I/usr/local/include hello.c
错误信息如下
/tmp/ccKeKpX9.o(.text+0x37): In function `main':
: undefined reference to `sqlite3_open'
/tmp/ccKeKpX9.o(.text+0x51): In function `main':
: undefined reference to `sqlite3_errmsg'
/tmp/ccKeKpX9.o(.text+0x73): In function `main':
: undefined reference to `sqlite3_close'
/tmp/ccKeKpX9.o(.text+0x9b): In function `main':
: undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status
那么,恭喜你中招了。错误根本不在SQLITE也不在你的程序,而在GCC。Gcc的编译参数是有顺序的。正确的编译命令是:
gcc -o hello -L /usr/local/lib -I/usr/local/include -static hello.c -lsqlite3
说实话,这么的一个小问题困扰了我一天的时间!真是菜啊~~~~~~
#include <stdlib.h>
#include <stdio.h>
#include "sqlite3.h"
int main(void)
{
sqlite3 *db=NULL;
char *zErrMsg = 0;
int rc;
rc=sqlite3_open("test1.db",&db);
if(rc)
{
fprintf(stderr,"Can't open database: %s\n",sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
else printf("open mydata successfully!\n");
sqlite3_close(db);
return 0;
}
用GCC来编译的时候总是会出现错误,编译的命令如下
gcc -static -o hello -lsqlite3 -L /usr/local/lib -I/usr/local/include hello.c
错误信息如下
/tmp/ccKeKpX9.o(.text+0x37): In function `main':
: undefined reference to `sqlite3_open'
/tmp/ccKeKpX9.o(.text+0x51): In function `main':
: undefined reference to `sqlite3_errmsg'
/tmp/ccKeKpX9.o(.text+0x73): In function `main':
: undefined reference to `sqlite3_close'
/tmp/ccKeKpX9.o(.text+0x9b): In function `main':
: undefined reference to `sqlite3_close'
collect2: ld returned 1 exit status
那么,恭喜你中招了。错误根本不在SQLITE也不在你的程序,而在GCC。Gcc的编译参数是有顺序的。正确的编译命令是:
gcc -o hello -L /usr/local/lib -I/usr/local/include -static hello.c -lsqlite3
说实话,这么的一个小问题困扰了我一天的时间!真是菜啊~~~~~~
相关文章推荐
- C++中Boost使用出现错误undefined reference to `boost::system::generic_category()'解决方法
- 移植uip-0.9到u-boot中出现undefined reference to `strstr'错误的解决过程
- 使用opencv 2.2静态库时: undefined reference to `clock_gettime' 链接错误问题解决
- undefined reference to `__gnu_mcount_nc'的解决 在编译内核时出现了如下错误:
- PHP 5.3.10 编译安装时出现 undefined reference to `libiconv' 错误的解决方法
- cocos2dx添加新的类后出现错误undefined reference to的解决办法
- 解决webrtc2sip编译出现错误undefined reference to symbol 'dlopen@@GLIBC_2.1'
- 编译3.10内核 出现错误 “undefined reference to...." 解决方法
- Libcurl使用OpenSSL编译出现undefined reference to `COMP_CTX_free'错误备忘
- jni中出现使用LOGD,出现undefined reference to '__android_log_print错误
- sqlite3 交叉编译 undefined reference to `fdatasync' 错误解决
- 解决使用NDK进行编译时出现undefined reference to function的问题
- STM32 GCC 使用 USB 库出现”undefined reference to _sbrk”问题解决
- 解决Laravel5.1使用composer update时出现Call to undefined method getCachedCompilePath()错误
- 解决 linux下使用eclipse调用gdal 出现undefined reference to `GDALAllRegister'问题
- GCC编译uboot出现(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'错误的解决的方法
- cocos2d-x 使用ndk编译 x86 出现 in function Curl_resolv_timeout: undefined reference to 'sigsetjmp' 错误
- 解决引用openssl静态库libcrypto.a和libssl.a出现undefined reference to错误的问题
- 编译时出现undefined reference to `libiconv_open’的解决办法
- 使用g++编译C/C++程序,链接时出现undefined reference to错误