This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
GCC "Name Mangling" Prevent from Linking?
- From: Chih-Wei Chiu <jwchiu at csie dot nctu dot edu dot tw>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 12 Apr 2002 20:48:46 +0800
- Subject: GCC "Name Mangling" Prevent from Linking?
- Organization: CGGM Lab, NCTU, Taiwan
Compiler: GCC 3.0.4
OS: RedHat Linux 6.2
I posted this question on both VTK and GCC-HELP mailing lists.
A progrm is successfully compile, link, and run on Windows with VTK 4.
It failes to link on Linux/FreeBSD.
I find a "potential problem." Uh...this may be "the problem," but if
not, 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?
Build log
=========
[jwchiu@cggmpc7 isosurface]$ make
g++ -L../../../polyobj/lib -L/usr/local/lib/vtk -o ../../bin/isosurface
/tmp/isosurface.o /tmp/Mesh.o /tmp/Volume.o -lpolyobj -lvtkPatented
-lvtkCommon -lvtkGraphics -lvtkIO -lvtkFiltering -lvtkRendering
-lvtkImaging
/tmp/isosurface.o: In function `main':
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:42: undefined
reference to `vtkVolume16Reader::New() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:43: undefined
reference to `vtkVolume16Reader::SetDataByteOrderToLittleEndian()
'/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:48: undefined
reference to `vtkMarchingCubes::New() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:49: undefined
reference to `vtkStructuredPointsSource::GetOutput() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:49: undefined
reference to
`vtkStructuredPointsToPolyDataFilter::SetInput(vtkImageData*) '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:52: undefined
reference to `vtkPolyDataMapper::New() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:53: undefined
reference to `vtkPolyDataSource::GetOutput() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:53: undefined
reference to `vtkPolyDataMapper::SetInput(vtkPolyData*) '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:55: undefined
reference to `vtkActor::New() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:58: undefined
reference to `vtkRenderer::New() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:61: undefined
reference to `vtkRenderWindow::New() '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:62: undefined
reference to `vtkRenderWindow::AddRenderer(vtkRenderer*) '
/home/jwchiu/cvs/fluid/src/isosurface/isosurface.cpp:73: undefined
reference to `vtkOBJExporter::New()
--
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