0

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

WalleyM
  • 172
  • 7
  • 1
    Adding include directories does not link a library. It just lets you find it's headers. – Jesper Juhl Jul 19 '20 at 20:52
  • https://stackoverflow.com/q/12573816/5910058 – Jesper Juhl Jul 19 '20 at 20:53
  • Did you define `tag.lib` as a linker input file? – Paul Sanders Jul 19 '20 at 21:05
  • @JesperJuhl I also included the library in additional dependencies – WalleyM Jul 19 '20 at 23:09
  • @JesperJuhl That question explains the error and I understand that the error is being caused by the linker not being able to find the definitions of the functions of the external libraries. I realise this must be due to how I've linked the library. That's where I can't work out where I've gone wrong – WalleyM Jul 19 '20 at 23:11
  • @PaulSanders I added it as an additional dependency. Is a linker input file a separate thing? – WalleyM Jul 19 '20 at 23:13
  • On Visual Studio it should be Linker -> Input->Additional Dependencies – drescherjm Jul 19 '20 at 23:52
  • `__declspec(dllimport)` says it's expecting an import library for a DLL and not a static libraray. An import library will have a `.lib` extension. My expectation is you need to enable BUILD_SHARED_LIBS and use the dll. Unless there is some macro required to be defined to use a static library for this taglib. – drescherjm Jul 19 '20 at 23:54

0 Answers0