简体   繁体   English

sqlite visual studio 2015

[英]sqlite visual studio 2015

I'm trying to make a program using sqlite and visual studio. 我正在尝试使用sqlite和Visual Studio制作程序。 I've added sqlite3.def, sqlite3.c, sqlite3.h, sqlite3.dll files to the project directory. 我已经将sqlite3.def, sqlite3.c, sqlite3.h, sqlite3.dll文件添加到项目目录中。 I've also added THREADSAFE and SQLITE_ENABLE_COLUMN_METADATA in the project settings to the preprocessor definitions and sqlite3.def in Linker -> Input -> Module definition file . 我还将项目设置中的THREADSAFESQLITE_ENABLE_COLUMN_METADATA添加到了Linker -> Input -> Module definition file的预处理器定义和sqlite3.def中。 I'm trying to compile the following program 我正在尝试编译以下程序

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


int main(int argc, char **argv)
{
    sqlite3* db;
    char* zErr;
    int rc;
    char* sql;

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

    if (rc)
    {
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(1);
    }

    sql = "create table episodes( id integer primary key,"
          "                       name text, cid int)";

    rc = sqlite3_exec(db, sql, NULL, NULL, &zErr);

    if (rc != SQLITE_OK)
    {
        if (zErr != NULL)
        {
            fprintf(stderr, "SQL error: %s\n", zErr);
            sqlite3_free(zErr);
        }
    }

    sql = "insert into episodes (name,id) values ('Cinnamon Babka2',1)";
    rc = sqlite3_exec(db, sql, NULL, NULL, &zErr);

    if (rc != SQLITE_OK)
    {
        if (zErr != NULL)
        {
            fprintf(stderr, "SQL error: %s\n", zErr);
            sqlite3_free(zErr);
        }
    }

    sqlite3_close(db);
    return 0;
}

And I get a whole bunch of errors, here are some of them: 我收到很多错误,其中一些是:

LNK2001 unresolved external symbol sqlite3_aggregate_context
LNK2001 unresolved external symbol sqlite3_backup_finish
LNK2001 unresolved external symbol sqlite3_backup_pagecount

My question is how to fix this? 我的问题是如何解决? Thanks! 谢谢!

There are two projects involved in this - the sqlite3.dll and the code you are writing. 这涉及两个项目-sqlite3.dll和您正在编写的代码。

main application 主要应用

This does not build the sqlite3 code, but does require the header file "sqlite3.h", and access to the library file which defines the functions in sqlite3.dll and the .dll to get them from. 这不会生成sqlite3代码,但确实需要头文件“ sqlite3.h”,并访问定义了sqlite3.dll和.dll中函数的库文件。

Don't add the .def (that describes what is being exported). 不要添加.def(描述正在导出的内容)。 Don't add the .c file. 不要添加.c文件。

  • In the linker settings. 在链接器设置中。
  • In General 一般来说

Add Additional Library Directories, the directory containing sqlite3.lib - In the linker settings. 添加其他库目录,该目录包含sqlite3.lib在链接器设置中。 - In Input Add sqlite3.lib to the Additional Dependencies. -在输入中,将sqlite3.lib添加到其他依赖项中。

Build a DLL with exports (sqlite3.dll) 用导出构建一个DLL(sqlite3.dll)

To build a DLL with exports, you need. 要使用导出构建DLL,您需要。

  1. A description of the files being exported (sqlite3.def) 导出文件的描述(sqlite3.def)
  2. Files to compile (sqlite3.c) 要编译的文件(sqlite3.c)

This creates a .lib file (description of the exports) and a .dll (implementation of the code). 这将创建一个.lib文件(对导出的描述)和一个.dll(代码的实现)。

Troubleshooting 故障排除

The Microsoft : Windows DDK includes an application called depends.exe. Microsoft:Windows DDK包含一个名为Depends.exe的应用程序。 This can be used to view a .DLL or .EXE imports and exports. 这可用于查看.DLL.EXE导入和导出。 This helps you identify if the DLL was correctly built. 这可以帮助您确定DLL是否正确构建。

The linker option /VERBOSE:LIB ( MSDN : /Verbose ) shows which files the linker is searching for import definitions. 链接器选项/ VERBOSE:LIB( MSDN:/ Verbose )显示链接器正在搜索导入定义的文件。

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

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