在 Visual Studio 2010 中使用 TagLib
编辑:是的,我看过这篇文章。不幸的是,看起来用户最终还是使用了 MingW。
我使用的是 64 位 Windows 7。我从 SVN 存储库下载了最新版本的 TagLib 代码。我正在使用修订版1202935。
我正在尝试在 Visual Studio 2010 中使用 TagLib。我已经让 TagLib 与 QtCreator/MingW 一起使用,但我想开始学习 Windows API,所以我从 Visual Studio 2010(当然是 C++)开始。
在VS2010中,我构建了zlib(静态和动态)以及带和不带zlib的TagLib(静态和动态)。换句话说,我已经尝试了一切我能想到的方法来让它发挥作用。
我的理想情况是使用 CMake 为 TagLib 生成 VS2010 项目文件(有一个用于 VS2010 64 位的选项。我不选择此选项)。我希望它们是静态库,因此我启用 ENABLE_STATIC,并启用WITH_ASF 和WITH_MP4。我还使用 ZLIB_INCLUDE_DIR 和 ZLIB_LIBRARY 将 TagLib 定向到 zlib(我链接到之前使用 VS2010 构建的 zlib.lib 文件)。请注意,我使用的是 CMake GUI。
然后,我在 VS2010 中打开生成的项目文件,并对代码进行三处更改,以便它在 Visual Studio 2010 中构建时不会出现错误(我将修复程序放在这里,以供与我遇到相同问题的其他人使用 )。
apefooter.cpp 第 192 行:
std::bitset<32> flags(static_cast<unsigned long long>(data.mid(20, 4).toUInt(false)));
mpcproperties.cpp 第 116 行:
std::bitset<32> flags = static_cast<unsigned long long>(d->data.mid(8, 4).toUInt(false));
mpegheader.cpp 第 171 行:
std::bitset<32> flags(static_cast<unsigned long long>(data.toUInt()));
然后我注释掉第 436 行和 mpegfile.cpp 中的 437,因为 我认为这是一个错误。
// ID3v2Tag(true);
// ID3v1Tag(true);
然后我在发布模式下构建项目。它构建得很好。没有错误(尽管有很多警告)。
所以我生成了tag.lib。然后我创建了一个测试 VS2010 项目/解决方案来使用 TagLib。
这是我使用 TagLib 的唯一一行。只是一个测试,请注意。
TagLib::MPEG::File a("tests/other/blank.mp3");
- 我将
TAGLIB_STATIC
添加到所有配置(发布和调试版本)的预处理器选项(属性页 > 配置属性 > C/C++ > 预处理器 > 预处理器定义) ) - 我将每一个该死的头目录添加到属性页>中配置属性> C/C++>一般>其他包含目录
- 最后,我按顺序将 zlib.lib 和 tag.lib 添加到其他依赖项(属性页 > 配置属性 > 链接器 > 输入 > 其他依赖项)
“哎呀!好麻烦啊!现在看看能不能成功?”
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)
其他人可以尝试我在这里所做的事情并指出我的错误吗?我试图提供足够的信息让大家看看发生了什么。
感谢您的阅读!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经能够使用 Visual Studio 2010 构建 TagLib 1.7。
我的步骤
从以下位置下载 zlib 源
http://zlib.net/
从以下位置下载 zlib bin
http://www.winimage.com/zLibDll/index.html
安装VC++ zlib 源目录
& bins
从以下位置下载 TagLib 1.7
http://developer.kde.org/~wheeler/taglib.html
提取taglib-1.7目录
使用命令提示符运行 - cmake -G "Visual Studio 10" in taglib-1.7目录
打开&构建taglib.sln
.dll 和 lib 文件转到 /taglib-1.7/taglib/Debug & /taglib-1.7/taglib/Release
使用 CMake gui 会引发 ZLIB 错误,手动添加 zlib 目录和 lib 将生成 Visual Studio 解决方案,但不会生成 .dll 文件(链接错误)
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)
问题是
__clrcall
。您没有提到您的项目是 C++/CLI,但这是一个非常重要的细节。人们使用其他库(例如 Oracle DB)时会遇到此问题。
让 Visual C++ 知道 taglib 是本机代码。
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.
to let Visual C++ know that taglib is native code.
在代码中定义宏“TAGLIB_STATIC”!
示例
#define TAGLIB_STATIC
define the macro "TAGLIB_STATIC" in your code!
example
#define TAGLIB_STATIC