[vtkusers] building static libraries using vtk libs

David Cole david.cole at kitware.com
Tue Nov 29 14:18:52 EST 2005


(re-cc'ing vtkusers at vtk.org : Please keep replies "on list" for the 
benefit of all... Just one person on the "To" list might not be able to 
respond in a timely manner.)

Are the redefined types in (A) your lib and a VTK lib or (B) in two 
different VTK libs?

If it's in your lib, I'll bet you are accidentally building some VTK 
symbols into your library... Figure out how and prevent it.

If it's two VTK libs, I'll bet you're giving the linker the VTK libs in 
a different order than CMake would. Try a test project with CMake and 
see what order it puts the VTK libs in...

Another issue to keep in mind is that compiler and linker flags *matter* 
when linking together projects in this manner. One of the benefits of 
using CMake is that it takes care of those messy details for you to 
guarantee build settings' consistency. (i.e. - don't change your 
threading model compiler flags, or switch from static to DLL builds of 
the C runtime libs without considering whether that's consistent with 
the VTK libs you're linking in...)

Be careful, you might take more time trying to do it without CMake than 
it would take to convert your really big project to using CMake.

:-)
David


Jesse Corrington wrote:

> Thanks for the reply, but I still have a question. Even when i link 
> the VTK libs into my project it still does not compile, because it 
> gets link errors about redefined types. Could this be because my 
> library project was created with cmake, and my other isn't. The exe 
> project i really don't want to make a cmake file for, because it is a 
> really big project and I don't want to waste time doing that when i 
> dont need to.
>
> Thanks for all the help
>
> Jesse Corrington
>
>
>> From: David Cole <david.cole at kitware.com>
>> To: Jesse Corrington <corrington_j at hotmail.com>
>> CC: vtkusers at vtk.org
>> Subject: Re: [vtkusers] building static libraries using vtk libs
>> Date: Tue, 29 Nov 2005 09:02:50 -0500
>>
>> When you link in static libraries, you must specify all the libraries 
>> for all the classes, functions and data you use. If you are simply 
>> linking in your own static library that "references" VTK libraries, 
>> you must also link in the VTK libraries that are used.
>>
>> CMake takes care of this automatically for you by tracking library 
>> dependencies. If you are using a CMake based build for both your exe 
>> and lib projects, there's probably a way to set it up so that all you 
>> have to do is TARGET_LINK_LIBRARIES to your lib and CMake will figure 
>> out the VTK part. If you're not using CMake for one of your projects, 
>> you have to link in all the VTK *.lib files that you need.
>>
>> Another idea would be to link VTK statically into a DLL of yours 
>> (rather than a static lib of yours). That way, the DLL is fully 
>> linked to VTK and you will only have to link to the import library 
>> for the DLL from other projects. (But if you do this, the VTK stuff 
>> will *not* be exported from that DLL... On second thought, maybe this 
>> isn't a good idea if the "other projects" need access to VTK stuff -- 
>> which clearly they do, or you wouldn't have undefined link errors in 
>> the first place. :-))
>>
>>
>> HTH,
>> David
>>
>> Jesse Corrington wrote:
>>
>>> So what I am trying to do Is build my own static library on windows 
>>> that uses some of the vtk libraries. The purpose is so i Can keep 
>>> the vtk stuff seperate from my current project and just link my one 
>>> lib in and use it. So i converted my one project that was produsing 
>>> an exe to make a windows static library file, and that is working 
>>> just fine.
>>>
>>> The problem is when i try to link my library that I built into 
>>> another project I get tons of link errors. Half of the link errors 
>>> are for undefined stuff in vtk. Do I have to link those into this 
>>> project too, shouldn't they already be in the library I built. I can 
>>> get rid of those errors by linking in the vtk libs i used to build 
>>> my lib, but then i Get a load of link erros that mainly said 
>>> something is already defined somewhere else. Some are stl, and other 
>>> basic functions. Any idea on how to fix this.
>>>
>>> Thanks a lot.
>>>
>>> Jesse Corrington
>>>
>>> _________________________________________________________________
>>> Express yourself instantly with MSN Messenger! Download today - it's 
>>> FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>>>
>>> _______________________________________________
>>> This is the private VTK discussion list. Please keep messages 
>>> on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>
> _________________________________________________________________
> Don’t just search. Find. Check out the new MSN Search! 
> http://search.msn.click-url.com/go/onm00200636ave/direct/01/
>
>



More information about the vtkusers mailing list