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

          說實話,這么的一個小問題困擾了我一天的時間!真是菜啊~~~~~~


          posted on 2013-01-10 14:05 姚先進 閱讀(2269) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
           
          主站蜘蛛池模板: 泰州市| 东莞市| 文山县| 枞阳县| 大同县| 车险| 天峻县| 崇左市| 重庆市| 都匀市| 巴彦县| 当涂县| 中宁县| 响水县| 加查县| 瑞金市| 汾西县| 台中市| 凉城县| 安徽省| 阳东县| 新乡市| 于都县| 吉林市| 鄂托克前旗| 象州县| 驻马店市| 青岛市| 霍州市| 阳山县| 平舆县| 清远市| 客服| 武穴市| 彭山县| 贺兰县| 浙江省| 武汉市| 芒康县| 衡阳市| 丰台区|