#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;
}
When compiling with GCC there is always an error, the compile command is as follows
gcc -static -o hello -lsqlite3 -L /usr/local/lib -I/usr/local/include hello.c
The error message is as follows
/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
The error is not in SQLITE nor in your program at all, but in GCC. the compilation parameters of Gcc are in order. The correct compile command is
gcc -o hello -L /usr/local/lib -I/usr/local/include -static hello.c -lsqlite3
Similar Posts:
- The source code installs the git tool, which shows /usr/local/lib64/libcrypto.a(dso_dlfcn.o) undefined reference to `dlopen’
- Undefined reference to ‘pthread’ appears in Linux Ubuntu running thread program_ Create ‘and undefined reference to’ pthread ‘_ ‘join’ error.
- Undefined reference to ` SEM appears when compiling with tcmalloc_ init’
- Hi3516DV300 Chip Error: “undefined reference to ×”
- undefined symbol: xxx – undefined reference to `typeinfo
- SVN:sqlite[S5]:database is locked [How to Solve]
- [How to Solve] SQLite database error: no such column
- undefined reference to ‘WinMain@16’
- Makefile:xxx: recipe for target ‘xxx’ failed
- C Compilation Error: implicit declaration of function xxx is invalid in C99 [-Wimplicit-function-declaration]