gpt4 book ai didi

c++ - (链接)Visual Studio 2010 中 Berkeley DB 的问题

转载 作者:太空宇宙 更新时间:2023-11-04 12:19:59 25 4
gpt4 key购买 nike

我正准备开始使用 Berkeley DB,我在此处下载了最新版本的 DB:Berkeley DB 5.1.25.msi Windows installer, with AES encryption

安装后我启动了 Visual Studio 2010 并执行了以下操作:

Project -> "project name" Properties -> VC++ Diretories -> include Directories

我添加了路径

C:\Program Files\Oracle\Berkeley DB 11gR2 5.1.25\include

然后我写了下面的代码:

#include<db_cxx.h>
#include<iostream>
using namespace std;


int main(){
Db db(NULL, 0); // Instantiate the Db object

return 0;
}

但它显示以下错误:

Error 1 error LNK2019: unresolved external symbol "public: virtual __thiscall Db::~Db(void)" (??1Db@@UAE@XZ) referenced in function _main C:\Users\Ahmed\documents\visual studio 2010\Projects\ssss\ssss\test.obj

Error 2 error LNK2019: unresolved external symbol "public: __thiscall Db::Db(class DbEnv *,unsigned int)" (??0Db@@QAE@PAVDbEnv@@I@Z) referenced in function _main C:\Users\Ahmed\documents\visual studio 2010\Projects\ssss\ssss\test.obj

Error 3 error LNK1120: 2 unresolved externals C:\Users\Ahmed\documents\visual studio 2010\Projects\ssss\Debug\ssss.exe 1

我尝试按照文档进行操作,我阅读了这篇 inf,但我不知道如何在 Visual Studio 2010 中应用它:

When building your application during development, you should normally use compile options "Debug Multithreaded DLL" and link against build_windows\Debug\libdb51d.lib. You can also build using a release version of the Berkeley DB libraries and tools, which will be placed in build_windows\Win32\Release\libdb51.lib. When linking against the release build, you should compile your code with the "Release Multithreaded DLL" compile option. You will also need to add the build_windows directory to the list of include directories of your application's project, or copy the Berkeley DB include files to another location.

最佳答案

您需要链接 Berkley DB 中包含的 .lib。可能有一个 C:\Program Files\Oracle\Berkeley DB 11gR2 5.1.25\lib 文件夹。您将需要添加此文件夹,或者可能需要添加适当的子文件夹。例如,可能有一个包含 x86 和 x64 子文件夹的 Windows 文件夹。您需要将适当的子文件夹添加到“库目录”中,该文件夹就在“包含目录”选项下方。

然后您必须向链接器指定要包含哪个 .lib。您应该查看软件的文档以了解需要哪一个。

VS2010中添加库依赖有两种方式。第一种方法是将以下代码行添加到项目中的适当位置(在您的代码片段中,它应该位于唯一源文件的最顶部)。

#pragma comment(lib, "filename.lib")

请注意,您的文件名需要用 "s 包裹,并且该行后面不应跟 ;。

另一种方法是在项目属性设置中添加名称。如果您转到项目设置->链接器->输入->附加依赖项。您应该会看到构建控制台应用程序所需的默认 .lib,例如 kernel32.lib、user32.lib 等。只需按照与添加其他包含文件夹相同的方式添加文件。

关于c++ - (链接)Visual Studio 2010 中 Berkeley DB 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5611831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com