[vtkusers] dll not found, unresolved externals, VTK 5.4.2, CMake 2.6, VS2008

David Cole david.cole at kitware.com
Tue Jun 30 10:28:50 EDT 2009


Chris,
I am not sure where you got this advice from, but it is a really, really bad
idea to copy any DLLs into the WINDOWS/system32 folder. Ever. Don't do it.
You'll regret it later...

The reason is that VTK dlls have the same name from release to release, but
they are not binary compatible with one another. You should keep VTK 5.4.2
dlls in their own installation folder (or copy them into your own
executable's folder) and reference them from there.

By the way, if you use CMake to build your project and reference VTK as
recommended in the VTK/Examples folder's (and sub-folders) CMakeLists.txt
files, then you would not have the unresolved externals problem in the first
place. CMake takes care of pulling in all the libraries you need without
specifying them all explicitly. (You specify the one you know you need, and
CMake pulls in the dependent libraries, too.)


HTH,
David


On Tue, Jun 30, 2009 at 7:18 AM, Chris Nater <mansch2001 at yahoo.com> wrote:

>
> Dear vtkusers,
>
> this seems to be a common problem when compiling VTK from source for the
> first time, especially for Visual Studio 8 & 9. After much trial-and-error I
> think I fixed it, so I will lay out possible solutions for unresolved
> externals, non-found dlls and general linker errors with VTK based on my
> recent experience.
>
> 0) Follow the exact instructions when compiling VTK from source using CMake
> and Visual Studio. A great guide is at
> http://code.hkpeterpeter.googlepages.com/vtk_build_vc.pdf.
>
> 1) If you BUILD_SHARED_LIBS when CMaking VTK from source, you will get a
> whole bunch of .dll as well as .lib files in your
> CMAKE_INSTALL_PREFIX/lib/vtkx.x.x folder. The best explanation of the
> difference between the two I have found is at
> http://www.codeguru.com/forum/archive/index.php/t-297139.html. Bottom
> line: if your VTK application stays on one machine, use the libs (static
> linkage and less possible redundancy). If you have dlls, copy them into the
> WINDOWS/system32 folder (WinXP).
>
> 2) In VS, also include the CMAKE_INSTALL_PREFIX/bin folder (full of .exes)
> in Tools->Options->Projects And Solutions->VC++ Directories->Library Files.
> They act as further compiled .obj files when linking (might not be necessary
> depending on your linking order or if you're using dlls).
>
> 3) One part of my problem had something to do with linking both dynamic and
> static libraries at the same time as well as in the wrong order. When using
> other non-standard libraries, such as nVidia's CUDA, and setting Additional
> Dependencies in Properties->Linker->Input, make sure they don't conflict
> with each other when calling standard libraries or dynamic versions of
> themselves in addition to static ones. Also, always include VTK headers
> after you include everything else. You can find out what the linker is
> searching for and when and how it fails on particular libraries by setting
> Properties->Linker->General->Show Progress to \VERBOSE:LIB.
>
> 4) The Runtime Library is set under Properties->C/C++->Code Generation. It
> needs to be consistent with how the VTK library has been built. If you want
> to run debug, you get debugging dlls linked which in turn reference other
> standard libraries, and I was basically getting a huge mess of conflicting
> libraries all trying to run in Release, Debug, and differently threaded
> modes simultaneously. Solution: check
> http://msdn.microsoft.com/en-us/library/aa278396(VS.60).aspx, understand
> how it works for your program and determine which one you need. \MDd worked
> for me.
>
> If you understand how C++ uses libraries, then you will solve your linker
> problems. If you are still getting fatal unresolved externals, LNK2019,
> LNK2001 or LNK1120 problems, then I recommend you type it into MSDN to get a
> detailed description. It's all down to your linking order, making sure you
> reference all the libraries you need, what mode your libraries where built
> in and by proxy what other non-standard, release libraries you are using
> (e.g. CUDA or ITK). If you don't use any other non-standard libraries, most
> of those weird conflicts will probably go away.
>
> You can test your installation with
> http://code.hkpeterpeter.googlepages.com/vtk_minimal.zip. Including that
> project_config.h when you don't have any dlls in your program will allow for
> static linkage without having to manually define Additional Dependencies in
> VS.
>
> If anyone is running into similar problems and none of this works, email me
> and I'll try to help.
>
> Cheers,
> Chris
>
>
>
> --- On *Fri, 6/26/09, Chris Nater <mansch2001 at yahoo.com>* wrote:
>
>
> From: Chris Nater <mansch2001 at yahoo.com>
> Subject: [vtkusers] dll not found, unresolved externals, VTK 5.4.2, CMake
> 2.6, VS2008
> To: vtkusers at vtk.org
> Date: Friday, June 26, 2009, 1:59 PM
>
>
> Hi all,
>
> I have followed all the instructions for compiling and installing VTK 5.4.2
> from source. CMake 2.6 was used to set the targets and I chose to
> BUILD_EXAMPLES and WRAP_TCL.
>
> ALL_BUILD was built inside VS2008, no errors and subsequently INSTALL was
> built, also no errors. I set the lib and include folders into VS2008 VC++
> Directories from the newly created CMAKE_INSTALL_PREFIX.
>
> I have run Peter's minimal VTK C++ project at
> http://code.hkpeterpeter.googlepages.com/vtk_minimal.zip (who runs a site
> with help for people compiling VTK from source to C++), and I get a Windows
> error "Unable to Locate Component", in this case "vtkFiltering.dll was not
> found". Where are these dlls in the first place? Do I need to manually move
> them to the Windows/system32 folder?
>
> Furthermore, my own VS2008 project has other issues with VTK. I #include
> vtkImageReader.h (which by itself compiles fine) but when I instantiate it
> with vtkImageReader::New(), I get a fatal "unresolved external symbol"
> error**. What else do I need to include?
>
> I tried #pragma comment(lib,"vtkIO.lib"), but that seems to send
> msvcprt.lib into disarray, stating that suddenly all the calls to stdlib and
> stdio functions in my program are "already defined", e.g. ***.
>
> What is going on here? Have I not installed VTK properly? Any thoughts or
> questions on this would be greatly appreciated. Thanks very much to all
> reading this long email.
>
> Best regards,
> Chris
>
>
>
> ** myclass.obj : error LNK2019: unresolved external symbol "public: static
> class vtkImageReader * __cdecl vtkImageReader::New(void)"
> (?New at vtkImageReader@@SAPAV1 at XZ) referenced in function "private: unsigned
> char * __thiscall myclass::loadRawFile(void)" (?loadRawFile at myclass
> @@AAEPAEXZ)
>
>
> *** msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class
> std::basic_istream<char,struct std::char_traits<char> > & __thiscall
> std::basic_istream<char,struct std::char_traits<char> >::seekg(long,int)"
> (?seekg@?$basic_istream at DU?$char_traits at D@std@@@std@@QAEAAV12 at JH@Z)
> already defined in myclass.obj
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090630/fafc0eaa/attachment.htm>


More information about the vtkusers mailing list