在 Visual Studio 2010 中使用包含非托管代码的 DLL?

发布于 2024-10-03 16:21:00 字数 808 浏览 1 评论 0 原文

我对 C++ 相当陌生,并试图弄清楚如何使用 TagLib 库 对于我正在从事的一个项目。我正在 Windows 7 64 位上的 Visual Studio 2010 中使用非托管 C++。我以前从未使用过外部库,所以我对如何解决这个问题感到非常困惑。

来自此博客条目我得到了 libtaglib.a 和 taglib.dll 文件。我遇到了这个SO问题使用 TagLib,但它涉及 QT Creator,而不是 Visual Studio,而且我对这个主题的了解不够,无法理解将其转化为 Visual Studio 需要完成的内容。

所以,有一些问题:

  • 是否可以使用非托管代码来做到这一点?
  • .a 文件的具体功能是什么?
  • 最重要的是,我如何在我的程序中使用 taglib.dll?

我一直在谷歌上寻找一种方法来做到这一点,但我的主要问题是我遇到的所有事情都超出了我的能力范围。如果需要更多信息,请告诉我。非常感谢任何帮助!谢谢!

I'm fairly new to C++ and an trying to figure out to use the TagLib library for a project I am working on. I'm working with unmanaged C++ in Visual Studio 2010 on Windows 7 64bit. I've never used an external library before so I'm very confused on how to go about this.

From this blog entry I got the libtaglib.a and taglib.dll files. I ran across this SO question on how to use TagLib, but it deals with QT Creator, not Visual Studio and I'm not knowledgeable enough about the subject to understand what is being said to translate it into what needs done for Visual Studio.

So, some questions:

  • Is it even possible to do this with unmanaged code?
  • What exactly is the function of a .a file?
  • Most importantly, how do I go about using the taglib.dll in my program??

I've been all over Google looking for a way to do this, but my major problem is that everything I run across is over my head. Please let me know if more info is required. Any help is very much appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

⊕婉儿 2024-10-10 16:21:00

我似乎已经成功地让它工作了。以下是我所做工作的粗略概述:

1.) 我使用 CMake 生成 Visual Studio 解决方案。

2.) 我尝试在VS解决方案中构建标签项目,但失败了。

3.) 我对一些源文件进行了更正,如下所述:http://old.nabble.com/taglib-fails-to-compile-with-MS-VC%2B%2B-2010-td29185593.html

4. )我在发布模式下再次构建了标签项目。这次成功了。

5.) 我将生成的 dll、def 和 lib 文件复制到与项目源文件相同的目录中。

6.) 我将头文件从 taglib 源复制到项目中的子目录(不确定这是否完全是一个好的做法)

7.) 在我的项目设置中,我将包含头文件的子目录设置为附加包含目录。

8.) 我通过添加>现有项目将 dll、exp 和 lib 文件添加到我的项目中。

9.) 我从 taglib 示例中添加了一些代码并构建了它。一切都很顺利,所以我想我明白了。

我遇到的一个警告是,由于 DLL 是在发布模式下构建的,因此我的项目必须在发布模式下运行,否则就会崩溃。我猜想如果我用内置的调试模式替换 DLL,我可以在调试模式下运行我的程序,但我还没有尝试过这一点。

I seem to have gotten it working successfully. Here's a rough outline of what I did:

1.) I used CMake to generate the Visual Studio solution.

2.) I attempted to build the tag project in the VS solution, but it failed.

3.) I made the corrections to a few source files as outlined here: http://old.nabble.com/taglib-fails-to-compile-with-MS-VC%2B%2B-2010-td29185593.html

4.) I built the tag project again in release mode. This time it was successful.

5.) I copied the resulting dll, def, and lib files to the same directory as the source files for my project.

6.) I copied the header files from the taglib source to a subdirectory in my project (not sure if this entirely good practice)

7.) In my project settings, I set the subdirectory with the header files as an additional include directory.

8.) I added the dll, exp, and lib files to my project by just going to Add>Existing Item.

9.) I added some code from the taglib examples and built it. Everything worked so I think I got it.

One caveat I ran into, since the DLL was built in release mode, my project had to be run in release mode or it would crash. I'm guessing that if I replaced the DLL with one built in debug mode I could run my program in debug mode, but I have not tried this.

ヤ经典坏疍 2024-10-10 16:21:00

您不能在 Visual Studio 中使用特定于 GCC 的库(您可以看出,因为它们具有 .a 扩展名)。您必须从源代码构建该库才能将其与 MSVC 一起使用。完成此操作后,只需将构建过程生成的 .lib 添加到您的项目即可,一切都应该开箱即用。 (请注意,无论是否为动态链接进行编译,您都需要它 - 在 msvc 领域中并不重要)

编辑 - 在查看 TagLib 本身之后 -

为了编译TagLib,您需要获取 CMake 构建系统TagLib 本身,并让 CMake 为您构建一个 Visual Studio 解决方案。使用该解决方案,您将能够构建所需的 .lib.dll。请注意,由于 TagLib 是一个 KDE 库,因此您可能还需要构建一些 QT 位才能使所有工作顺利进行。然而,我对图书馆没有具体的经验,所以我不会在这里提供太多帮助。

You cannot use libraries specific to GCC (you can tell because they have .a extensions) with Visual Studio. You will have to build the library from source in order to use it with MSVC. Once you have done that it's a simple matter of adding the .lib generated from the build process to your project and things should work out of the box. (Note that it's a .lib you need whether you're compiling for dynamic linking or not -- doesn't matter in msvc land)

EDIT -- after looking at TagLib itself --

In order to compile TagLib you'll need to get the CMake build system, and TagLib itself, and have CMake build you a visual studio solution. Using that solution you'll be able to build the .libs and .dlls you need. Note that because TagLib is a KDE library, you'll probably need to also build some QT bits in order for everything work work successfully. However, I don't have specific experience with the library so I'm not going to be all that helpful here.

心如荒岛 2024-10-10 16:21:00

如果您有 .dll 文件,则不必重新编译源代码(以创建 .lib 文件)。使用 dumpbin /exports 和 lib(两者都随 Visual Studio 一起提供),您可以创建一个可以与您的应用程序链接的库。在此链接中,您可以看到一个很好的解释: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/

但正如比利所说,可能您需要 QT 的其他部分才能使用该库。

Yo do not have to recompile the source (to create the .lib file) if you have the .dll file. With dumpbin /exports and lib (both came with Visual Studio) yo can create a lib that you can link with your application. In this link you can see a nice explanation: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/

But as Billy Said, probably you would need other parts of QT to use this library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文