Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ DLL文件中的SQLite3函数导致无法解析外部_C++_Visual Studio_Dll_Sqlite - Fatal编程技术网

C++ DLL文件中的SQLite3函数导致无法解析外部

C++ DLL文件中的SQLite3函数导致无法解析外部,c++,visual-studio,dll,sqlite,C++,Visual Studio,Dll,Sqlite,我正在VisualStudio2008中创建一个DLL,它需要使用SQLite3。我已经包含了找到的文件sqlite3.h。现在我的文件只有一个函数,它只需要一个参数,即数据库名,然后打开它。我的档案如下: DBOPEN.H #include <string> using namespace std; __declspec(dllexport) bool OpenDatabase(std::string); 值得一提的是,我以前从未写过DLL,我是根据我在网上的各种资源中找到的格式

我正在VisualStudio2008中创建一个DLL,它需要使用SQLite3。我已经包含了找到的文件sqlite3.h。现在我的文件只有一个函数,它只需要一个参数,即数据库名,然后打开它。我的档案如下:

DBOPEN.H

#include <string>
using namespace std;
__declspec(dllexport) bool OpenDatabase(std::string);
值得一提的是,我以前从未写过DLL,我是根据我在网上的各种资源中找到的格式编写的。但是,当我尝试构建此文件时,会出现以下错误:

1>dbopen.obj : error LNK2019: unresolved external symbol _sqlite3_open referenced in function "bool __cdecl OpenDatabase(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?OpenDatabase@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\me\Documents\Visual Studio 2008\Projects\dbopen\Debug\dbopen.dll : fatal error LNK1120: 1 unresolved externals
1>dbopen.obj:错误LNK2019:未解析的外部符号\u sqlite3\u open在函数“bool\uuuu cdecl OpenDatabase(class std::basic\u string)”(?OpenDatabase@@YA\u NV?$basic)中引用_string@DU?$char_traits@D@性病病毒$allocator@D@2@@@std@@@Z)
1> C:\Users\me\Documents\Visual Studio 2008\Projects\dbopen\Debug\dbopen.dll:致命错误LNK1120:1未解析的外部

老实说,我真的不知道如何解决这个问题。我尝试过切换各种事物、更改函数定义等,但sqlite3_open不断导致错误。我注意到,如果我尝试使用其他sqlite3函数,它们都会给出相同的错误,但是sqlite3对象定义可以工作。有人知道如何解决这个问题吗?提前感谢您的帮助

确保使用
\uuuu declspec(dllimport)bool OpenDatabase(std::string)。通常,您使用的宏将在标头中从dllexport切换到dllimport,具体取决于您是在构建dll还是在使用库。它使用一个额外的定义来实现这一点,您在构建dll时在预处理器设置中启用该定义。@drescherjm谢谢,那么应该将该定义添加到源文件中的声明中,因为头文件已经使用了dllexport?通常您会将头文件修改为类似于
MyExport bool OpenDatabase(std::string)的内容其中,在构建dll时,MyExport定义为
\uuudeclspec(dllexport)
,或者在使用dll时,MyExport定义为
\uuudeclspec(dllimport)
。我会看看是否能找到一个例子,因为这是很常见的。请确保仅在dll的预处理器定义中定义库\ U导出。在dll中,您如何链接到sqlite3库,或者是否将sqlite3源作为dll项目的一部分?
1>dbopen.obj : error LNK2019: unresolved external symbol _sqlite3_open referenced in function "bool __cdecl OpenDatabase(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?OpenDatabase@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\me\Documents\Visual Studio 2008\Projects\dbopen\Debug\dbopen.dll : fatal error LNK1120: 1 unresolved externals