<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-1252">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.4417.0">
<TITLE>c++ vtk compilation in RH Linux avoiding &quot;undefined reference&quot;</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><TT><FONT SIZE=2>Having seen a number of posts about &quot;undefined reference&quot; problems<BR>
when compiling c++ code that calls vtk libraries, and NOT seeing<BR>
posts that answered the question, I thought I'd write up the steps<BR>
I used to get past this for a RedHat Linux installation...<BR>
<BR>
(1) working with VTK_4.2.2, which was installed per the directions<BR>
&nbsp;&nbsp;&nbsp; using cmake -i (in wizard mode) and enabling shared libraries<BR>
&nbsp;&nbsp;&nbsp; saying YES to advanced options and asking to build all examples.<BR>
<BR>
(2) after running the wizard, I ran make, then make test, (long)<BR>
&nbsp;&nbsp;&nbsp; then make install to do the initial setup of VTK.<BR>
<BR>
(3) the make install put the vtk include files here:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /usr/local/include/vtk<BR>
&nbsp;&nbsp;&nbsp; and vtk the lib files here:<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /usr/local/lib/vtk<BR>
<BR>
(4) next I cd into my home directory and make a src dir for vtk<BR>
&nbsp;&nbsp;&nbsp; and copy the example code I found in the html documentation<BR>
&nbsp;&nbsp;&nbsp; supplied for vtk at this URL:<BR>
<BR>
&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp; /Examples/Build/vtkMy/Examples/Cxx/Ex2/vtkmyEx2.cxx<BR>
<BR>
&nbsp;&nbsp;&nbsp; which is relative to the html file set you can download.<BR>
&nbsp;&nbsp;&nbsp; (note that I changed the extension to cpp rather than cxx)<BR>
<BR>
&nbsp;&nbsp;&nbsp; so now I have the file vtkmyEx2.cpp in my home/src dir.<BR>
<BR>
(5) I create a&nbsp; makefile that looks like this:(remember to use tabs<BR>
&nbsp;&nbsp;&nbsp; rather than spaces to start the lines after the label vtkmyEx2:<BR>
&nbsp;&nbsp;&nbsp; line)<BR>
<BR>
&nbsp;&nbsp;&nbsp; #------makefile----------------------<BR>
&nbsp;&nbsp;&nbsp; VTKLIBPATH = /usr/local/lib/vtk<BR>
&nbsp;&nbsp;&nbsp; VTKINCPATH = /usr/local/include/vtk<BR>
<BR>
&nbsp;&nbsp;&nbsp; vtkmyEx2: vtkmyEx2.cpp<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g++ -o vtkmyEx2 -L$(VTKLIBPATH) -I$(VTKINCPATH) \<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -lvtkIO -lvtkRendering -lvtkGraphics \<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -lvtkzlib -lvtkFiltering -lvtkCommon -ldl \<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkmyEx2.cpp<BR>
&nbsp;&nbsp;&nbsp; #---end-makefile---------------------<BR>
<BR>
(6) next I ran make (just the plain gnu make, not cmake)<BR>
<BR>
&nbsp;&nbsp;&nbsp; Note that until I specified the path to the includes<BR>
&nbsp;&nbsp;&nbsp; and the path to the libraries and listed the libraries<BR>
&nbsp;&nbsp;&nbsp; I got either &quot;vtkRenderer.h not found&quot; type errors or<BR>
&nbsp;&nbsp;&nbsp; &quot;undefined reference: vtkRenderer::New()&quot; type errors.<BR>
<BR>
(7) make compiles and links an executable for you. Mine is called<BR>
&nbsp;&nbsp;&nbsp; vtkmyEx2<BR>
<BR>
&nbsp;&nbsp;&nbsp; but if you were to try to run it now ...<BR>
&nbsp;&nbsp;&nbsp; you will get an error telling you that you can't find<BR>
&nbsp;&nbsp;&nbsp; the shared libraries.&nbsp; Here is how you fix that for now:<BR>
<BR>
(8) In the bash shell, type:<BR>
<BR>
&nbsp;&nbsp;&nbsp; export LD_LIBRARY_PATH=:/lib:/usr/local/lib:/usr/local/lib/vtk<BR>
<BR>
&nbsp;&nbsp;&nbsp; (or if you already have this variable set, you might try...)<BR>
&nbsp;&nbsp;&nbsp; export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/vtk<BR>
<BR>
(9) Now try to execute your program.&nbsp;<BR>
<BR>
&nbsp;&nbsp;&nbsp; To make the LD_LIBRARY_PATH permanent, you need to add a line<BR>
&nbsp;&nbsp;&nbsp; similar to the above export to your .bashrc file in your home<BR>
&nbsp;&nbsp;&nbsp; directory. ( if you are using the c shell try setenv ... )<BR>
<BR>
(10) Your mileage may vary ...<BR>
<BR>
&nbsp;&nbsp;&nbsp; These notes are for a vanilla RedHat7.3 installation with<BR>
&nbsp;&nbsp;&nbsp; standard directory structure.<BR>
<BR>
&nbsp;&nbsp;&nbsp; The key points are telling g++ where to look for include<BR>
&nbsp;&nbsp;&nbsp; files via the -I directive, and where to look for lib files<BR>
&nbsp;&nbsp;&nbsp; via the -L directive (both of these want just the path, not<BR>
&nbsp;&nbsp;&nbsp; the specific files) then listing the various vtk libs you<BR>
&nbsp;&nbsp;&nbsp; are using via the -l directives.&nbsp; Finally, you want to make<BR>
&nbsp;&nbsp;&nbsp; sure your system can find the shared libraries you have<BR>
&nbsp;&nbsp;&nbsp; referenced by setting the LD_LIBRARY_PATH environment variable.<BR>
<BR>
&nbsp;&nbsp;&nbsp; Good luck.<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</FONT></TT>
</P>

</BODY>
</HTML>