I have been trying to statically link the TagLib library to a project in Visual Studio 2019.
So far my project will build however as soon as I declare anything from the TagLib library I get an error saying: Unresolved External Symbol.
Specifically, I try creating an instance of FileRef from the file fileref.h. This causes errors:
Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl TagLib::FileName::FileName(char const *)" (_imp??0FileName@TagLib@@QEAA@PEBD@Z) referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl TagLib::FileRef::FileRef(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (_imp??0FileRef@TagLib@@QEAA@VFileName@1@_NW4ReadStyle@AudioProperties@1@@Z) referenced in function main
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl TagLib::FileRef::~FileRef(void)" (_imp??1FileRef@TagLib@@UEAA@XZ) referenced in function main
As far as I understand it from looking this problem up in related issues this means the linker can find the function declarations from the external library but not the definitions. I assume this is due to me linking the library incorrectly. One source I used was this: What is an undefined reference/unresolved external symbol error and how do I fix it?
I installed the library using cmake with BUILD_SHARED_LIBS=off and ENABLE_STATIC_RUNTIME=on. For all INSTALL_DIR parameters (INCLUDE/LIB/EXEC/BIN) I used the default setting which was a folder in Program Files (x86). These were also put into their own folders (e.g. "C:/Program Files (x86)/taglib/include"). I had read that sometimes spaces in VS file paths can cause problems and so I attempted moving the files installed into this directory into a new directory with no spaces and linking from there. However this did not fix the error.
Once TagLib was installed, I linked it through the Visual Studio settings:
Additional Include Directories: C:\Program Files %28x86%29\taglib\include\taglib;%(AdditionalIncludeDirectories)
Additional Library Directories: C:\Program Files %28x86%29\taglib\lib;%(AdditionalLibraryDirectories)
Additional Dependencies: tag.lib
I can't seem to work out where I am going wrong with this linking and was wondering if anyone else had any ideas?
Thanks