简体   繁体   English

Visual Studio 2015(C ++)sqlite3.dll无法解析的外部符号

[英]Visual Studio 2015 (C++) sqlite3.dll unresolved external symbol

I cannot figure out how to get sqlite3.dll (or any dll for that matter) to work with my C++ project in Visual Studio. 我无法弄清楚如何使sqlite3.dll(或与此相关的任何dll)与Visual Studio中的C ++项目一起使用。

The error message I get is LNK2001 unresolved external symbol sqlite3_open 我收到的错误消息是LNK2001无法解析的外部符号sqlite3_open

Here's what I did so far: 这是我到目前为止所做的:

  • I put the .dll in myProjectFoler/Resources/sqlite3.dll 我将.dll放在myProjectFoler / Resources / sqlite3.dll中
  • I generated sqlite3.lib using Visual Studio Developer Command Prompt using a command lib /def:sqlite3.def 我使用Visual Studio Developer命令提示符使用命令lib /def:sqlite3.def生成了sqlite3.lib
  • I referenced the directory with the lib in Project -> Preferences -> Linker -> General -> Additional Library directories , and then referenced the .lib in Project -> Preferences -> Linker -> Input-> Additional dependencies 我在项目->首选项->链接器->常规->其他库目录中引用了带有lib的目录 ,然后在项目->首选项->链接器->输入->其他依赖项中引用了.lib
  • I placed sqlite3.h in my project and #included it 我在项目中放入了sqlite3.h并包含了它

(pretty much followed the instructions seen here ) (大致遵循此处显示的说明)

Thank you for help 谢谢你的帮助

The issue is that by default the header file assumes that sqlite is linked statically, as opposed to dynamic linking to a dll. 问题是默认情况下,头文件假定sqlite是静态链接的,而不是动态链接到dll。

This part of sqlite3.h is responsible for that: sqlite3.h的这一部分负责:

#ifndef SQLITE_API
# define SQLITE_API
#endif

If you set a per-project define in project properties: 如果您在项目属性中设置每个项目的定义,请执行以下操作:

SQLITE_API=__declspec(dllimport)

this should resolve your link error. 这样可以解决您的链接错误。 Alternatively, you can put 或者,您可以放

#define SQLITE_API __declspec(dllimport)

right before where you #include sqlite3.h. 在#include sqlite3.h之前。

It's difficult to tell exactly why the problem occurred. 很难确切说明问题发生的原因。 There are lots of reasons which could cause LNK2001 error. 有很多原因可能会导致LNK2001错误。 MSDN contains good check list. MSDN包含良好的检查清单。

You could try to use /VERBOSE option to determine which files the linker references. 您可以尝试使用/VERBOSE选项来确定链接器引用的文件。 Put this option in Project -> Preferences -> Linker -> Command Line -> Additional Options . 将此选项放在Project -> Preferences -> Linker -> Command Line -> Additional Options Output should contains similar strings: 输出应包含类似的字符串:

Searching e:\SQLite\sqlite-dll-win32-x86-3150100\sqlite3.lib:
      Found _sqlite3_open
         Referenced in ConsoleApplication2.obj
         Loaded sqlite3.lib(sqlite3.dll)

Pay attention to the VS runtime libraries, there should be no mixup between Debug and Release libraries. 注意VS运行时库,在Debug和Release库之间不应混为一谈。

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

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