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

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


          網站導航:
           
           
          主站蜘蛛池模板: 凤凰县| 双牌县| 新沂市| 鹤山市| 萝北县| 纳雍县| 同心县| 贵南县| 沙田区| 新乡县| 霍林郭勒市| 晋宁县| 潞西市| 平安县| 保山市| 武隆县| 德江县| 巨野县| 石棉县| 高安市| 怀安县| 千阳县| 汝州市| 环江| 湘阴县| 昌乐县| 礼泉县| 额济纳旗| 个旧市| 康保县| 龙州县| 伽师县| 凤台县| 滦平县| 双鸭山市| 娱乐| 林口县| 青阳县| 福安市| 惠来县| 龙口市|