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