开发者

Using a DLL with unmanaged code in Visual Studio 2010?

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 Googl开发者_Python百科e 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!


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜