我不想编译动态库,因此this question没用。
我下载了taglib并使用以下方法编译它:
cmake -DENABLE_STATIC=ON -DENABLE_STATIC_RUNTIME=ON -DWITH_MP4=ON -G "Visual Studio 10"
生成Visual Studio解决方案,我可以编译“tag”项目,该项目在taglib / Release中生成tag.lib。
当我尝试在测试应用程序中使用库时出现问题 - 没什么,只是一个简单的测试:
#include "stdafx.h"
#include "fileref.h"
int _tmain(int argc, _TCHAR* argv[])
{
TagLib::FileRef d("");
return 0;
}
我收到以下链接器错误:
Error 1 error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall TagLib::FileRef::~FileRef(void)" (__imp_??1FileRef@TagLib@@UAE@XZ) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 2 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TagLib::FileRef::FileRef(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (__imp_??0FileRef@TagLib@@QAE@VFileName@1@_NW4ReadStyle@AudioProperties@1@@Z) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 4 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TagLib::FileName::FileName(char const *)" (__imp_??0FileName@TagLib@@QAE@PBD@Z) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 3 error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TagLib::FileName::~FileName(void)" (__imp_??1FileName@TagLib@@QAE@XZ) C:\...\taglib_test\taglib_test\taglib_test.obj taglib_test
Error 5 error LNK1120: 4 unresolved externals C:\...\taglib_test\Release\taglib_test.exe taglib_test
有人可以告诉我这里发生了什么吗?
以下是标签项目中预处理器的定义:
WIN32
_WINDOWS
NDEBUG
HAVE_CONFIG_H
_CRT_SECURE_NO_DEPRECATE
_CRT_NONSTDC_NO_DEPRECATE
TAGLIB_STATIC
CMAKE_INTDIR="Release"
答案 0 :(得分:7)
对于遇到此问题的人: 我通过在测试项目中定义TAGLIB_STATIC来修复它:
#include "stdafx.h"
//This should have been generated by the build system in taglib_config.h
//but was not.
#define TAGLIB_STATIC
#include "fileref.h"
int _tmain(int argc, _TCHAR* argv[])
{
TagLib::FileRef d("");
return 0;
}