linking error

I have this vtk (www.vtk.org) example i got from wiki. It compiles and executes perfectly. Its a very small piece of code.

I have a different c++ project which consists of several files. Now, i insert the headers from the vtk example and the lines of code into my main(). When i attempt to build this, I get a linking error of the form

skipping incompatible /usr/lib/libvtkCommon.so when searching for -lvtkCommon

for every libvtk file. Now, all of these lib files work perfectly for the same lines of code when placed in a separate file. Just when i insert in main() for my project spanning multiple files, the code compiles fine but cannot be linked.

Any suggestions as to what I am doing wrong ?
Heres an update. I converted the wiki example main() to a function line(), I have a created a main() in a separate file which just calls this line() and does nothing else.

1
2
3
4
5
6
//  Line.cpp
#include "SEVERAL_VTK_HEADERS"
int line(){
do_some_stuff
return 0;
}


1
2
3
4
5
6
// main.cpp
int line();
int main(){
line();
return 0;
}


I compile these files using g++ -I/include_dir_path -c Line.cpp main.cpp and this gives no error. But when i try to link this using g++ main.o Line.o -L/Lib_dir_path -SEVERAL_VTK_LIBS the linker complains about incompatible libraries. Next, if i just convert the function line() to main() in Line.cpp, then the code works as expected. I do not know what is going on.

Can anyone help me with this please ?

Thanks,
Copy and paste your:

1. compile commands
2. link commands
3. error output from your link commands
1
2
3
4
5
6
7
// This works fine
g++ -c main.cpp Line.cpp -I/usr/local/include/vtk-5.0/

// This gives an error
g++ main.o Line.o -L/usr/local/lib/vtk-5.0/ -lvtkCommon -lvtkHybrid -lvtkGenericFiltering 
-lvtkVolumeRendering -lvtksys -lvtkFiltering -lvtkRendering -lvtkIO -lvtkGraphics -lvtkexoIIc -lvtkNetCDF -lvtkImaging 
-lvtkftgl -lvtkfreetype -lvtkDICOMParser -lvtkpng -lvtktiff -lvtkzlib -lvtkjpeg -lvtkexpat  -o prog


1
2
/usr/bin/ld: skipping incompatible /usr/local/lib/vtk-5.0/libvtkCommon.so when searching for -lvtkCommon
/usr/bin/ld: skipping incompatible /usr/local/lib/vtk-5.0/libvtkHybrid.so when searching for -lvtkHybrid

and so on.. for every libvtk file.
I just figured out what was going on. I needed a flag -m32 and now everything works as expected. But i am not sure why this is the case though. Any suggestions ?
Are you running on a 64-bit machine? Perhaps vtk was built using a 32bit gcc?
yes, that is precisely what it was. Should have figured it out on my own. Spent a day and half on this. Lesson learnt.
Topic archived. No new replies allowed.