Using TagLib in Visual Studio 2010

无人久伴 提交于 2019-12-30 07:31:08

问题


EDIT: Yes, I have looked at this post. Unfortunately, it looks like the user ends up using MingW in the end.


I am on Windows 7, 64-bit. I downloaded the most recent version of the TagLib code from the SVN repository. I am using revision 1202935.

I am trying to use TagLib in Visual Studio 2010. I have gotten TagLib to work with QtCreator/MingW, but I want to start learning the Windows API so I am starting from scratch in Visual Studio 2010 (C++ of course).

In VS2010, I have build zlib (both statically and dynamically) and TagLib with and without zlib (both statically and dynamically). In other words, I have tried everything I can think of to get this to work.

My ideal situation is that I use CMake to generate the VS2010 project files (there is an option for VS2010 64-bit. I do not choose this option) for TagLib. I would like them to be static libraries, so I enable ENABLE_STATIC, and I enable WITH_ASF, and WITH_MP4. I also direct TagLib to zlib using ZLIB_INCLUDE_DIR and ZLIB_LIBRARY (I am linking to the zlib.lib file that I previously built using VS2010). Note, I am using the CMake GUI.

I then open up the generated project files in VS2010 and make three changes to the code so that it build in Visual Studio 2010 without error (I put the fixes here for anyone else who had the same problem as I).

apefooter.cpp on line 192:

std::bitset<32> flags(static_cast<unsigned long long>(data.mid(20, 4).toUInt(false)));

mpcproperties.cpp on line 116:

std::bitset<32> flags = static_cast<unsigned long long>(d->data.mid(8, 4).toUInt(false));

mpegheader.cpp on line 171:

std::bitset<32> flags(static_cast<unsigned long long>(data.toUInt()));

I then make then comment out lines 436 and 437 in mpegfile.cpp, because I think it's a bug.

// ID3v2Tag(true);
// ID3v1Tag(true);

I then build the project in Release mode. It builds just fine. No errors (although there are a bunch of warnings).

So I have generated tag.lib. I then created a test VS2010 project/solution to use TagLib.

This is the only line I use TagLib. Just a test, mind you.

TagLib::MPEG::File a("tests/other/blank.mp3");
  • I added TAGLIB_STATIC to the preprocessor options (Property Pages > Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions) for all configurations (both Release and Debug builds)
  • I added every single darn header directory to Property Pages > Configuration Properties > C/C++ > General > Additional Include Directories
  • And finally I added zlib.lib and tag.lib to the additional dependencies (Property Pages > Configuration Properties > Linker > Input > Additional Dependencies) IN THAT ORDER

"Whew! What a hassle! Now let's see if it works?"

1>vs_taglib_test.obj : error LNK2028: unresolved token (0A00001A) "public: virtual __clrcall TagLib::MPEG::File::~File(void)" (??1File@MPEG@TagLib@@$$FUAM@XZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>vs_taglib_test.obj : error LNK2028: unresolved token (0A00001B) "public: __clrcall TagLib::MPEG::File::File(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (??0File@MPEG@TagLib@@$$FQAM@VFileName@2@_NW4ReadStyle@AudioProperties@2@@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>vs_taglib_test.obj : error LNK2019: unresolved external symbol "public: virtual __clrcall TagLib::MPEG::File::~File(void)" (??1File@MPEG@TagLib@@$$FUAM@XZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
1>vs_taglib_test.obj : error LNK2019: unresolved external symbol "public: __clrcall TagLib::MPEG::File::File(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (??0File@MPEG@TagLib@@$$FQAM@VFileName@2@_NW4ReadStyle@AudioProperties@2@@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

Can someone else try out what I'm doing here and point out my mistake? I tried to provide enough information for y'all to see what's happening.

Thanks for reading!


回答1:


I've been able to build TagLib 1.7 using Visual Studio 2010.

My Steps

  • Download zlib sources from http://zlib.net/

  • Download zlib bins from http://www.winimage.com/zLibDll/index.html

  • Setup VC++ Directories to zlib source & bins

  • Download TagLib 1.7 from http://developer.kde.org/~wheeler/taglib.html

  • Extract taglib-1.7 directory

  • Use command prompt to run - cmake -G "Visual Studio 10" in taglib-1.7 directory

  • Open & build taglib.sln

  • .dll and lib files go to /taglib-1.7/taglib/Debug & /taglib-1.7/taglib/Release

Using the CMake gui throws up errors for ZLIB and adding the zlib directories and lib manually will generate a visual studio solution but it would not generate the .dll files (linking errors)




回答2:


The problem is __clrcall. You didn't mention that your project is C++/CLI but that's a very important detail.

People have run into this with other libraries, like Oracle DB.

#pragma managed(push, off)
#include "taglib.h"
#pragma managed(pop)

to let Visual C++ know that taglib is native code.



来源:https://stackoverflow.com/questions/4413949/using-taglib-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!