[vtkusers] GCC "Name Mangling" Prevent from Linking VTK?

Chih-Wei Chiu jwchiu at csie.nctu.edu.tw
Fri Apr 12 08:40:32 EDT 2002


This is a following post of:

"Fail to link with static VTK 4 on Linux (but succeed on Windows)"

I find a "potential problem." Uh...this may be "the problem," but would
you convince me why this works?

I doubted it's because the compiler performed different name mangling
scheme to my program and VTK library, and that's why linker failed.

To see why, run `nm' on dump the `symbol' used by
vtkMarchingCubes::New()

[ccbsd7]~>nm /usr/local/lib/vtk/libvtkPatented.a | grep MarchingCubes |
grep New
	 ....(omitted)...
         U New__16vtkMarchingCubes
         U New__21vtkImageMarchingCubes
00000000 T New__16vtkMarchingCubes

While my program gets:

[ccbsd7]~>nm /tmp/isosurface.o |grep MarchingCubes
         U _ZN16vtkMarchingCubes3NewEv
00000000 W _ZN16vtkMarchingCubes8SetValueEif

I guess the linker complained `undefined reference' because the function
vtkMarchingCubes::New() is called New__16vtkMarchingCubes in VTK, while
it's called _ZN16vtkMarchingCubes3NewEv in my program's object file.
Why?



VTK: 4.0
Compiler: GCC 3.0.4
OS: RedHat Linux 6.2 (same problem on FreeBSD too)
compiler options: -g -O2

--
Chih-Wei Chiu <http://www.csie.nctu.edu.tw/~jwchiu>
Computer Graphics and Geometry Modeling Laboratory,
Computer Science and Information Engineering Department,
National Chiao-Tung University, Taiwan



More information about the vtkusers mailing list