[osg-users] OSG2.4 and 2.5.5 Windows static build problems

Philip Lowman philip at yhbt.com
Mon Jul 21 04:55:02 PDT 2008


On Mon, Jul 21, 2008 at 5:21 AM, Stephan Maximilian Huber <
ratzfatz at digitalmind.de> wrote:

> Christiansen, Brad schrieb:
>
>> Hi,
>>
>> I have searched the archive but cant find any mention of the problem,
>> though I think can remember reading about a solution some time ago on
>> the list.
>>
>> I have just tried to build the static version of OSG v2.4 and v2.5.5
>> using ViualStudio .Net 2003. When I do this build I get 5000+ warnings
>> about dulpicate definitions when linking (LNK 4006). I then cannot link
>> my aplication against the resulting .libs. Has anyone else encountered
>> this problem and have a fix / workaround?
>>
> Are these link-errors related to OpenThreads? A quick and dirty fiy would
> be:
>
> change CMakeLists for all osg-libs/src from
>
> IF   (DYNAMIC_OPENSCENEGRAPH)
>   ADD_DEFINITIONS(-DOSG_LIBRARY)
> ELSE (DYNAMIC_OPENSCENEGRAPH)
>   ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
> ENDIF(DYNAMIC_OPENSCENEGRAPH)
>
>
> to
>
> IF   (DYNAMIC_OPENSCENEGRAPH)
>   ADD_DEFINITIONS(-DOSG_LIBRARY)
> ELSE (DYNAMIC_OPENSCENEGRAPH)
>   ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)
>   ADD_DEFINITIONS(-DOT_LIBRARY_STATIC)
> ENDIF(DYNAMIC_OPENSCENEGRAPH)
>
>
> The underlying problem is:
>
> The setting, that you compiled OpenThreads statically is not carried out to
> a public header or something. If another lib includes a header-file of
>  OpenThreads the compiler thinks, that OpenThreads is linked for
> dynamic-usage (because OT_LIBARY_STATIC is not defined so the
> EXPORT-definition for OpenThreads is not setup correctly), so you'll get
> multiple defined symbols, when you try to link your app with static
> OpenThreads and static osg, because osg includes OpenThreads-symbols for
> dynamic-linking.
>
> IMHO the definition of OT_LIBARY_STATIC should be carried out to
> OpenThreads/Config. The same should be done for OSG_LIBRARY_STATIC. On Linux
> there's no such problem, because you don't have to declare different exports
> for static versus dynamic linking.
>
> I am no expert in CMake, so perhaps somebody may jump in here?


You can add OT_LIBRARY_STATIC to OpenThreads/Config but it does rule out the
ability to #include the same set of headers and alternate between a static
and a shared library version of OpenThreads on MSVC.  It's not uncommon to
ship a "foo.lib" and a "foo_static.lib" or "foo_a.lib" with a particular
library so the user can choose between either.  It would be relatively easy
to add this to OpenThreads one day if it was desired (also generation of
libOpenThreads.a) but it would be impossible to arbitrate between the two on
MSVC (without using separate install prefixes) if the selection was done in
the OpenThreads/Config header file.

I'd say the right thing to do in this case is to push this issue to the user
actually linking against the code, in other words the OSG, with the initial
fix you suggested.

-- 
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080721/b9c6b9a1/attachment-0003.htm>


More information about the osg-users mailing list