[vtkusers] LNK2019: unresolved external symbol, missing function from .def file

Goldman, Jon jgoldma at sandia.gov
Thu Jul 10 15:22:52 EDT 2008


I was getting an unresolved external symbol linker error on Windows recently, when linking with VTK. I wanted to document what happened, should anybody else encounter a similar problem.

The sequence of events:

1. Built VTK locally from source on a Windows box with BUILD_SHARED_LIBS enabled.

2. The application that linked with VTK reported a LNK2019 error on _vtk_TIFFMergeFieldInfo. Sample output from Visual Studio 2005 follows:

1>------ Build started: Project: stack-test, Configuration: Debug Win32 ------
2>------ Build started: Project: Monkey, Configuration: Debug Win32 ------
3>------ Build started: Project: ImageDataToMeshData-test00, Configuration: Debug Win32 ------
1>Linking...
3>Linking...
2>Linking...
1>chimp.lib(ImageData.obj) : error LNK2019: unresolved external symbol _vtk_TIFFMergeFieldInfo referenced in function "public: virtual int __thiscall ImageData::saveAsTiff(int,class QString)" (?saveAsTiff at ImageData@@UAEHHVQString@@@Z)
3>chimp.lib(ImageData.obj) : error LNK2019: unresolved external symbol _vtk_TIFFMergeFieldInfo referenced in function "public: virtual int __thiscall ImageData::saveAsTiff(int,class QString)" (?saveAsTiff at ImageData@@UAEHHVQString@@@Z)
1>C:\build\libchimp\Tests\Unit\Debug\stack-test.exe : fatal error LNK1120: 1 unresolved externals
3>C:\build\libchimp\Tests\Unit\Debug\ImageDataToMeshData-test00.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\build\libchimp\Tests\Unit\stack-test.dir\Debug\BuildLog.htm"
1>stack-test - 2 error(s), 0 warning(s)
3>Build log was saved at "file://c:\build\libchimp\Tests\Unit\ImageDataToMeshData-test00.dir\Debug\BuildLog.htm"
3>ImageDataToMeshData-test00 - 2 error(s), 0 warning(s)
2>chimp.lib(ImageData.obj) : error LNK2019: unresolved external symbol _vtk_TIFFMergeFieldInfo referenced in function "public: virtual int __thiscall ImageData::saveAsTiff(int,class QString)" (?saveAsTiff at ImageData@@UAEHHVQString@@@Z)
2>C:\build\libchimp\GUI\Debug\Monkey.exe : fatal error LNK1120: 1 unresolved externals
2>Build log was saved at "file://c:\build\libchimp\GUI\Monkey.dir\Debug\BuildLog.htm"
2>Monkey - 2 error(s), 0 warning(s)
4>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug Win32 ------
4>Project not selected to build for this solution configuration
========== Build: 0 succeeded, 3 failed, 3 up-to-date, 1 skipped ==========

3. I used the Windows dumpbin.exe file to dump the symbols in vtktiff.dll and noticed that vtk_TIFFMergeFieldInfo was missing:

   C:\build\VTK-trunk\bin\release> dumpbin/exports vtktiff.dll
   ...
   25   18 000195E0 vtk_TIFFIsTiled
   26   19 00003730 vtk_TIFFLastDirectory       <---- expected vtk_TIFFMergeFieldInfo to follow this entry
   27   1A 00003640 vtk_TIFFNumberOfDirectories
   ....

4. Looking at the source files for VTK/Utilities/vtktiff, it appeared the function was well defined...

5. ...and rebuilding VTK with BUILD_SHARED_LIBS disabled, i.e. as static libraries, the linker error went away.

6. Turns out that the module-definition (.def) file for vtktiff, i.e. vtktiff.def, was missing the entry "vtk_TIFFMergeFieldInfo". Which meant TIFFMergeFieldInfo was not being exported by the DLL.

7. Adding "vtk_TIFFMergeFieldInfo" to vtkdiff.def, and rebuilding VTK as shared libraries fixed the problem. Here dumpbin shows the symbol exported correctly:

   C:\build\VTK-trunk\bin\release> dumpbin/exports vtktiff.dll
   ...
   26   19 00003730 vtk_TIFFLastDirectory
   27   1A 00003A80 vtk_TIFFMergeFieldInfo
   28   1B 00003640 vtk_TIFFNumberOfDirectories
   ...





More information about the vtkusers mailing list