ubuntu sqlite3源码编译

1、首先从SQLite Download Page网站下载最新sqlite3源码,

2、选择sqlite3.c和sqlite3.h,sqlite3ext.h加载到工程中。

3、编写测试main.c函数:

#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"

int main()
{
    sqlite3 *db;
    int nResult = sqlite3_open("test.db", &db);
    if(nResult == SQLITE_OK)
    {
        printf("open success\n");
    }
    else
    {
        printf("open fail\n");
    }

    return 0;
}

4、编写命令行命令:gcc -o main main.c sqlite3.c -lpthread -ldl -lm

如果不加上-lpthread -ldl -lm,则会报错,报错信息如下:

/usr/bin/ld: sqlite3.o: in function `pthreadMutexAlloc':
sqlite3.c:(.text+0x436e): undefined reference to `pthread_mutexattr_init'
/usr/bin/ld: sqlite3.c:(.text+0x437f): undefined reference to `pthread_mutexattr_settype'
/usr/bin/ld: sqlite3.c:(.text+0x439e): undefined reference to `pthread_mutexattr_destroy'
/usr/bin/ld: sqlite3.o: in function `pthreadMutexTry':
sqlite3.c:(.text+0x4473): undefined reference to `pthread_mutex_trylock'
/usr/bin/ld: sqlite3.o: in function `sqlite3ThreadCreate':
sqlite3.c:(.text+0x93ec): undefined reference to `pthread_create'
/usr/bin/ld: sqlite3.o: in function `sqlite3ThreadJoin':
sqlite3.c:(.text+0x9482): undefined reference to `pthread_join'
/usr/bin/ld: sqlite3.o: in function `unixDlOpen':
sqlite3.c:(.text+0x125a9): undefined reference to `dlopen'
/usr/bin/ld: sqlite3.o: in function `unixDlError':
sqlite3.c:(.text+0x125cc): undefined reference to `dlerror'
/usr/bin/ld: sqlite3.o: in function `unixDlSym':
sqlite3.c:(.text+0x1261f): undefined reference to `dlsym'
/usr/bin/ld: sqlite3.o: in function `unixDlClose':
sqlite3.c:(.text+0x12659): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
make: *** [Makefile:12: main] Error 1

编译参考How To Compile SQLite

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值