如何使用sqlite3.c在一个C ++项目? [英] How can I use sqlite3.c in a c++ project?

查看:239
本文介绍了如何使用sqlite3.c在一个C ++项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Eclipse一个C ++项目中使用sqlite3的,发现意见很大在线上使用API​​,但不幸的是我在较早的障碍落下。我想这是因为我缺乏与C / C ++和CDT经验。
我简单地复制sqlite3.c和sqlite3.h到项目的源文件夹,并有一个测试方法,该方法如下:

I am attempting to use sqlite3 in a C++ project in Eclipse and have found a great deal of advice online on using the API, but unfortunately am falling at an earlier hurdle. I guess this is due to my lack of experience with C/C++ and CDT. I've simply copied sqlite3.c and sqlite3.h into the project's source folder and have a test method which is as follows:

int main() {
    sqlite3* db;
    sqlite3** dbpointer = &db;
    const char* dbname = "test.db";
    sqlite3_open(dbname, dbpointer);
    return 0;
}

不过,sqlite3.c文件显示在Eclipse无数错误。例如,下面的部分用'现场'IN_DECLARE_VTAB注明无法得到解决。

However, the sqlite3.c file shows up in Eclipse with numerous errors. For example, the following section is annotated with 'Field 'IN_DECLARE_VTAB' could not be resolved'.

#ifdef SQLITE_OMIT_VIRTUALTABLE
  #define IN_DECLARE_VTAB 0
#else
  #define IN_DECLARE_VTAB (pParse->declareVtab)
#endif

当我尝试编译我得到像一系列的错误:

When I try to compile I get a series of errors like:

 gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/sqlite3.d" -MT"src/sqlite3.d" -o "src/sqlite3.o" "../src/sqlite3.c"
../src/sqlite3.c:30997: error: initializer element is not constant
../src/sqlite3.c:30997: error: (near initialization for `aSyscall[0].pCurrent')
../src/sqlite3.c:30997: error: initializer element is not constant
../src/sqlite3.c:30997: error: (near initialization for `aSyscall[0]')
../src/sqlite3.c:31009: error: initializer element is not constant
../src/sqlite3.c:31009: error: (near initialization for `aSyscall[1]')
../src/sqlite3.c:31017: error: initializer element is not constant
../src/sqlite3.c:31017: error: (near initialization for `aSyscall[2]')

我没有找到一个类似的问题这里,但它不会出现已经要么有得到解决。

I did find a similar question here, but it doesn't appear to have been resolved there either.

我怀疑这是用Eclipse一个设置问题,因此,如果任何人都可以给我任何建议或有用的教程我真的AP preciate它的方向。如果我会更好张贴这样一个专用的源码论坛只是让我知道。

I suspect this is a set-up issue with Eclipse, so if anyone could give me any advice or directions to useful tutorials I'd really appreciate it. And if I'd be better off posting this to a dedicated sqlite forum just let me know.

推荐答案

你有没有这样尝试一下呢? (带双指针):

Have you try in this way? (with double pointer):

int main() {
    sqlite3* db;
    const char* dbname = "test.db";
    sqlite3_open(dbname, &db);
    return 0;
}

我想你是在Linux上运行。结果
另一种方法是执行一个脚本:

I suppose you're working on linux.
Another approach is to execute a script:

int main() {
  system("connectDB.sh"); 
  /* connectDB.sh should be chmod +x */
}

您的文件connectDB将是:

Your file connectDB will be:

#!/bin/bash
sqlite3 test.db "select * from test.table" 

这篇关于如何使用sqlite3.c在一个C ++项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆