加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLite C/C++ 编译

发布时间:2020-12-12 19:38:44 所属栏目:百科 来源:网络整理
导读:对于如下使用SQLite 的C/C++程序, #include stdio.h #include sqlite3.h int main( int argc, char * argv[]){ sqlite3 *db; char *zErrMsg = 0 ; int rc; rc = sqlite3_open( "test.db" ,db); if ( rc ){ fprintf (stderr, "Can't open database: %sn" ,s

对于如下使用SQLite 的C/C++程序,

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

int main(int argc,char* argv[])
{
   sqlite3 *db;
   char *zErrMsg = 0;
   int rc;

   rc = sqlite3_open("test.db",&db);

   if( rc ){
      fprintf(stderr,"Can't open database: %sn",sqlite3_errmsg(db));
      exit(0);
   }else{
      fprintf(stderr,"Opened database successfullyn");
   }
   sqlite3_close(db);
}

如果直接编译
gcc test_sqlite.cpp -o test_sqlite

会发生如下错误

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

起原因是没有将SQLite的lib链接进来。解决方法如下:

  1. 如果你是用的是Xcode一类的IDE,如图所示添加对libsqlite3的引用。

  2. 如果你是在terminal使用gcc编译,需要指定sqlite编译选项:
    gcc test_sqlite.cpp -l sqlite3

  3. Makefile的方法还在学习中,后续补充。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读