當前位置:編程學習大全網 - 源碼下載 - 調用sqlite_bind_XX函數出現錯誤undefined reference to''sqlite_bind_XX''

調用sqlite_bind_XX函數出現錯誤undefined reference to''sqlite_bind_XX''

假設妳已經正確編譯和安裝了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

  • 上一篇:MySQL如何使用索引 較為詳細的分析和例子_MySQL
  • 下一篇:2020雲臺山開放了嗎免費門票-民宿優惠
  • copyright 2024編程學習大全網