简体   繁体   English

我无法让Eclipse MinGW和Sqlite一起为C程序工作

[英]I cannot get Eclipse MinGW and Sqlite to Work Together for a C program

So I have spent the whole day trying to figure this out, and alas I have failed. 因此,我花了一整天的时间试图弄清楚这一点,可惜我失败了。 I need help! 我需要帮助! So I installed Eclipse and MinGW so that I can write a C program. 因此,我安装了Eclipse和MinGW,以便可以编写C程序。 I am new to all of this. 我是所有新手。 I need to be able to access an sqlite database. 我需要能够访问sqlite数据库。 So I downloaded the sqlite amalgamation and unzipped it to C:/sqlite3 and it contains two .c files and two .h files. 因此,我下载了sqlite合并,并将其解压缩到C:/ sqlite3,它包含两个.c文件和两个.h文件。 In the examples, I have seen online they include the sqlite.h header file as follows: 在示例中,我在线看到它们包含sqlite.h头文件,如下所示:

#include <sqlite.h>

So I think that I need to add an includes folder holding my sqlite info. 所以我认为我需要添加一个包含我的sqlite信息的包含文件夹。 So I click on my project and select Properties>C/C++ General>Paths and Symbols. 因此,我单击我的项目,然后选择“属性”>“ C / C ++常规”>“路径和符号”。 With the "Includes" tab selected and the Language GNU C highlighted, I add the Include directory C:\\sqlite3. 选择“包含”选项卡并突出显示语言GNU C之后,我添加了包含目录C:\\ sqlite3。 So far no problems, I can build a project that prints my name in the console. 到目前为止,没有问题,我可以构建一个在控制台上打印我的名字的项目。

Now I add some sample code from a tutorial site: 现在,我从教程站点添加一些示例代码:

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

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

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

   if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      return(0);
   }else{
      fprintf(stderr, "Opened database successfully\n");
   }
   sqlite3_close(db);
}

I get 3 errors claiming undefined reference to the sqlite3 functions. 我收到3个错误,声称未定义对sqlite3函数的引用。 So I think I need to add a link to sqlite3 in the compiler. 所以我想我需要在编译器中添加指向sqlite3的链接。 So now I go to Properties>C/C++ Build/Settings and add -lsqlite3 to the MinGW C Linker Command line. 所以现在我去Properties> C / C ++ Build / Settings并将-lsqlite3添加到MinGW C Linker命令行。 Now my errors disappear when I build the project, but I get a compile error that says this: 现在,在构建项目时,我的错误消失了,但是出现了一个编译错误,内容如下:

c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/6.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsqlite3

It looks like it is looking for the sqlite3 files in the MinGW directories. 看起来它正在MinGW目录中寻找sqlite3文件。 I am stuck. 我被困住了。 I have tried pasting the file in the MinGW directory and even that doesn't work. 我尝试将文件粘贴到MinGW目录中,即使这样也不起作用。 I know that I am missing something obvious to the world, but I only have about 5 pieces of hair left on my head and could really use some insight. 我知道我缺少世界上显而易见的东西,但我的头上只剩下5根头发,可以真正利用一些洞察力。 Please help me to get Eclipse set up using MinGW and accessing Sqlite. 请帮助我使用MinGW设置Eclipse并访问Sqlite。 Thanks! 谢谢!

The amalgamation is supposed to be compiled together with your other source files. 合并应该与您的其他源文件一起编译。 Just add the .c file to your project, as if it were one of your own source files. 只需将.c文件添加到您的项目中,就好像它是您自己的源文件之一一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM