title: Static linking external library problems - Visual Studio 2019
body: <p>I have been trying to statically link the TagLib library to a project in Visual Studio 2019.</p>
  <p>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.</p>
  <p>Specifically, I try creating an instance of FileRef from the file fileref.h. This causes errors:</p>
  <blockquote>
  <p>Main.obj : error LNK2019: unresolved external symbol &quot;__declspec(dllimport) public: __cdecl TagLib::FileName::FileName(char
  const *)&quot; (_<em>imp</em>??0FileName@TagLib@@QEAA@PEBD@Z) referenced in
  function main</p>
  <p>1&gt;Main.obj : error LNK2019: unresolved external symbol
  &quot;__declspec(dllimport) public: __cdecl TagLib::FileRef::FileRef(class
  TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)&quot;
  (_<em>imp</em>??0FileRef@TagLib@@QEAA@VFileName@1@_NW4ReadStyle@AudioProperties@1@@Z)
  referenced in function main</p>
  <p>1&gt;Main.obj : error LNK2019: unresolved external symbol
  &quot;__declspec(dllimport) public: virtual __cdecl
  TagLib::FileRef::~FileRef(void)&quot; (_<em>imp</em>??1FileRef@TagLib@@UEAA@XZ)
  referenced in function main</p>
  </blockquote>
  <p>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: <a href="https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix">What is an undefined reference/unresolved external symbol error and how do I fix it?</a></p>
  <p>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. &quot;C:/Program Files (x86)/taglib/include&quot;). 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.</p>
  <p>Once TagLib was installed, I linked it through the Visual Studio settings:</p>
  <p>Additional Include Directories:
  C:\Program Files %28x86%29\taglib\include\taglib;%(AdditionalIncludeDirectories)</p>
  <p>Additional Library Directories:
  C:\Program Files %28x86%29\taglib\lib;%(AdditionalLibraryDirectories)</p>
  <p>Additional Dependencies:
  tag.lib</p>
  <p>I can't seem to work out where I am going wrong with this linking and was wondering if anyone else had any ideas?</p>
  <p>Thanks</p>