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.
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.
// 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
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 ?