[Cmake] Specifying static or dynamic linking of external libraries?

Bill Hoffman bill.hoffman at kitware.com
Tue Oct 22 13:54:59 EDT 2002


See my recent post to the vtk users list.   In short, static libraries have
to be in a specific order.

So, I can see two problems:

1. This is the wrong order:
-lvtkCommon -lvtkRendering -lvtkHybrid -lvtkImaging -lvtkGraphics -lvtkFiltering -lvtkIO 
Any symbols in vtkCommon that are needed by vtkRendering will be skipped.

2. The vtkDynamicLoader class needs -ldl to link because it calls dlopen and dlclose.

So, if you changed the order and added -ldl it should work.
Both of these are not really cmake issues.  However, if you used cmake to compile
test, then it would get the library order correct.

-Bill

At 10:32 AM 10/22/2002 -0700, Thomas Deschamps wrote:
>Ok,
>
>I've specified the complete name (and I had to remove all the *.so files).
>I'm trying to link against  VTK static libraries.
>But the thing is I had a lot of errors of this kind:
>   g++ -rdynamic -g test.o  -L/usr/local/lib -lvtkCommon -lvtkRendering -lvtkHybrid -lvtkImaging -lvtkGraphics -lvtkFiltering -lvtkIO -Wl,-rpath,/usr/local/lib  -o testImagePlaneWidget
>   /usr/local/lib/libvtkCommon.a(vtkDynamicLoader.o): In function `vtkDynamicLoader::OpenLibrary(char const *)':
>   /home/users/deschamp/Tools/VTK/Common/vtkDynamicLoader.cxx:226: undefined reference to `dlopen'
>   /usr/local/lib/libvtkCommon.a(vtkDynamicLoader.o): In function `vtkDynamicLoader::CloseLibrary(void *)':
>   /home/users/deschamp/Tools/VTK/Common/vtkDynamicLoader.cxx:231: undefined reference to `dlclose'
>
>which means that the flag CMAKE_DL_LIBS (='ldl') is not used by cmake.... but why?
>
>Therefore I included it in the CMAKE_CXX_MODULE_LINK_FLAGS
>
>But it was not included again. I decided to include it in CMAKE_CXX_SHLIB_LINK_FLAGS, just to see what's happening.
>The result was it included "-ldl" in the command line, which means it is still using shared libraries linking while I am giving him only static libraries, strange isn't it?
>
>Sincerely, I do not understand what is going on, and why cmake is doing all those things.
>
>The final problem I have is that even with including the "-ldl" somewhere it is still not working, giving errors like
>
>   /usr/local/lib/libvtkRendering.a(vtkActor.o): In function `vtkActor::SetMapper(vtkMapper *)':
>   /home/users/deschamp/Tools/VTK/Rendering/vtkActor.cxx:529: undefined reference to `vtkAbstractMapper::RemoveConsumer(vtkObject *)'
>   /home/users/deschamp/Tools/VTK/Rendering/vtkActor.cxx:536: undefined reference to `vtkAbstractMapper::AddConsumer(vtkObject *)'
>   /usr/local/lib/libvtkRendering.a(vtkDataSetMapper.o): In function `vtkDataSetMapper::SetInput(vtkDataSet *)':
>   /home/users/deschamp/Tools/VTK/Rendering/vtkDataSetMapper.cxx:47: undefined reference to `vtkProcessObject::SetNthInput(int, vtkDataObject *)'
>
>Apparently it does not find any of the vtk stuff.
>
>Does anyone has been able to compile and use the static libraries?
>
>Thomas
>
>SP: I'm going to send this post to vtkusers mailing list also
>
>_______________________________________________
>Cmake mailing list
>Cmake at public.kitware.com
>http://public.kitware.com/mailman/listinfo/cmake





More information about the CMake mailing list