[问题] 什么都对了就是不能连接库文件undefined reference to '.....'

软件和网站开发以及相关技术探讨
回复
头像
halida
帖子: 246
注册时间: 2006-12-30 19:50

[问题] 什么都对了就是不能连接库文件undefined reference to '.....'

#1

帖子 halida » 2007-05-29 18:04

源程序在这:
什么都不用看,编译是正确的,使用了一些函数:
sqlite3_open
之类,就是不能连接,报错;
demo_sql.c:(.text+0xdd): undefined reference to `sqlite3_open'
我不知道gcc工作原理,也看不懂这个提示。


#include <stdio.h>
#include<stdlib.h>
#include <sqlite3.h>

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; i++){
printf("%s = %s\n", azColName, argv ? argv : "NULL");
}
printf("\n");
return 0;
}

int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int rc;

if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]);
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
讨厌free software
怀念卖软件的时代
头像
halida
帖子: 246
注册时间: 2006-12-30 19:50

#2

帖子 halida » 2007-05-29 18:05

哪位大哥指点一二?
讨厌free software
怀念卖软件的时代
antonym55
帖子: 353
注册时间: 2007-04-03 9:52
联系:

#3

帖子 antonym55 » 2007-05-29 19:36

没用过SQLite, 编译时加上 -lsqlite3 试试
头像
halida
帖子: 246
注册时间: 2006-12-30 19:50

#4

帖子 halida » 2007-05-30 8:11

晕,还要指定连接sqlite3.....
不能自动的。。。
讨厌free software
怀念卖软件的时代
antonym55
帖子: 353
注册时间: 2007-04-03 9:52
联系:

#5

帖子 antonym55 » 2007-05-30 9:15

halida 写了:晕,还要指定连接sqlite3.....
不能自动的。。。
这个太正常了吧,目前还没发现有什么可以自动的,

visual studio 也要指定一些才能链接,

你man 一下一般会说明要链接的文件
头像
halida
帖子: 246
注册时间: 2006-12-30 19:50

#6

帖子 halida » 2007-05-30 21:34

看来我懂的实在是太少了,都被IDE给蒙蔽了阿。
讨厌free software
怀念卖软件的时代
回复