<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><br>Dear vtkusers,<br><br>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.<br><br>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.<br><br>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).<br><br>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).<br><br>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.<br><br>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.<br><br>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.<br><br>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.<br><br>If anyone is running into similar problems and none of this works, email me and I'll try to help.<br><br>Cheers,<br>Chris<br><br><br><br>--- On <b>Fri, 6/26/09, Chris Nater <i><mansch2001@yahoo.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From:
Chris Nater <mansch2001@yahoo.com><br>Subject: [vtkusers] dll not found, unresolved externals, VTK 5.4.2, CMake 2.6, VS2008<br>To: vtkusers@vtk.org<br>Date: Friday, June 26, 2009, 1:59 PM<br><br><div id="yiv878120033"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">Hi all,<br><br>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.<br><br>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.<br><br>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?<br><br>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?<br><br>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. ***.<br><br>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.<br><br>Best regards,<br>Chris<br><br><br><br>** myclass.obj : error LNK2019: unresolved external symbol "public: static class vtkImageReader * __cdecl vtkImageReader::New(void)" (?New@vtkImageReader@@SAPAV1@XZ) referenced in function "private: unsigned char * __thiscall myclass::loadRawFile(void)" (?loadRawFile@myclass@@AAEPAEXZ)<br><br><br>*** 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@DU?$char_traits@D@std@@@std@@QAEAAV12@JH@Z) already defined in myclass.obj<br></td></tr></tbody></table><br>
</div><br>-----Inline Attachment Follows-----<br><br><div class="plainMail">_______________________________________________<br>Powered by www.kitware.com<br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br></div></blockquote></td></tr></table><br>