linux下的sqlitte3的編譯安裝和使用

來源:互聯網
上載者:User

http://19831028.blog.51cto.com/1333653/301419

http://blog.csdn.net/androidbluetooth/article/details/6573588

安裝好了,但是沒有編譯出庫檔案 ,好像不能開發應用程式調用API

sqlite3 資料庫命令操作 sqlite3資料庫與mysql資料庫的匯入匯出http://www.cnblogs.com/wdpp/archive/2011/11/30/2386714.html

執行sqlite3_exec查詢整個資料庫的時候,回呼函數怎麼能 返回全部的查詢結果,

struct olt_info
{

    int olt_index;
    int olt_logo;
    char* olt_line;
    // int nmber;
};

int my_callback(void *olt_temp, int argc, char *value[], char *name[])
{
    struct olt_info *pdata = NULL;
    pdata = (struct olt_info *)olt_temp;

    int jj;
    for (int i = 0; i < argc; i++)
        jj = printf("%s == %s\n", name[i], value[i]);

    pdata->olt_index = (int)atoi(value[0]);
    pdata->olt_logo = (int)atoi(value[1]);
    pdata->olt_line = value[2];

    return 0;
}

這樣可以列印,但是 不能返回。 這樣做的話只能返回最後一個。無法全部返回。。請問怎麼才能全部返回??

這個回呼函數在每得到一行結果的時候就會執行一次,所以pdata的的內容一直在變化。而你只能得到最後一行的結果。

試試用鏈表或隊列來儲存? [/quote]

  cp -rf /mnt/hgfs/share /home 複製檔案到目錄下

http://tech.ddvip.com/2007-10/119338075236567.html

Sqlite資料庫轉Mysql程式http://www.sqlite.com.cn/MySqlite/6/377.Html

問題1:

經過半天的努力,終於在vim下敲打出了第一個C程式,可是使用編譯命令後, gcc hello.c,出現如下結果,我不知道是哪的錯,請高手指點。
-----------------------------------------------------------------------------------------------------------
-bash-3.1$ gcc hello.c
hello.c: 在函數 ‘main’ 中:
hello.c:5: 錯誤:程式中有游離的 ‘\241’
hello.c:5: 錯誤:程式中有游離的 ‘\261’
hello.c:5: 錯誤:‘Hello’ 未聲明 (在此函數內第一次使用)
hello.c:5: 錯誤:(即使在一個函數內多次出現,每個未聲明的標識符在其
hello.c:5: 錯誤:所在的函數內只報告一次。)
hello.c:5: 錯誤:expected ‘)’ before ‘World’
hello.c:5: 錯誤:程式中有游離的 ‘\’
hello.c:5: 錯誤:程式中有游離的 ‘\241’
hello.c:5: 錯誤:程式中有游離的 ‘\261’

你的Hello World兩邊的引號怎麼用了中文的引號呢?
我給你帖一個,你仔細比較一下引號。
#include <stdio.h>

int main()
{
        printf("Hello World!\n");
        return 0;
}


問題2:undefined reference to `sqlite3_open'

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



確認make install正確無誤後,運行
ldconfig (man ldconfig, see FILES section。或者先將/usr/local/lib加入/etc/ld.so.conf。看情況你的sqlite是被安裝/usr/local下)
然後
ldconfig -p | grep libsqlite
確認。
編譯器時
gcc -o executible -L/usr/local/lib -lsqlite src.c

建議info gcc/ld/Makefile

  這是因為gcc找不到定義sqlite3_open等等的標頭檔,經過在網上尋找資料,

    找到瞭解決方法,使用如下的方法進行編譯:

    $ gcc -o hello -L /usr/local/sqlite-autoconf-3070400/lib -I/usr/local/sqlite-autoconf-307040/include sqlitetest.c  -lsqlite3

    上面的編譯主要意義時-L 代碼你安裝sqlite3類庫所在的路徑, -I代表安裝sqlite3的標頭檔路徑 而-l表示

    可執行程式的名稱

    經過上面的編譯,即可成功。

    執行結果如下:

    ~$ ./hello

    資料庫連接成功!

    插入資料成功

    插入資料成功

    查詢資料庫內容

    userid = 張三

    age = 20

    birthday = 2011-7-23

    userid = 李四

    age = 20

    birthday = 2012-9-20

    資料庫關閉成功!

http://blog.sina.com.cn/s/blog_7516537d0100tedt.html 警告:隱式聲明與內建函數 ‘memcpy’ 不相容”和一些標頭檔

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.