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