[Insight-developers] Multiply defined symbols with MSVC and BUILD_SHARED_LIBS=ON

Tom Vercauteren tom.vercauteren at m4x.org
Wed May 12 05:53:17 EDT 2010


Hi all,

I haven't figured out how to solve this duplicate symbol issue yet.
The only current workaround I have is to remove the NrrdIO and
DICOMImageIO2 from ITK...

Anyone against me committing a unit test based on the one I put on the
bug tracker?
  http://www.itk.org/Bug/file_download.php?file_id=3097&type=bug

For the record, regarding the mix between shared and static libaries
on MSVC when BUILD_SHARED_LIBS is on, I seem to understand that it is
mainly linked to the fact that there is no use of
__declspec(dllexport/dllimport) in a few third party libraries: vxl,
nifti and slatec. Cf.
  FAQ 3 of http://vxl.sourceforge.net/vxl-users-faq.html
  Comment on dllexport in
http://www.itk.org/cgi-bin/viewcvs.cgi/CMakeLists.txt?root=Insight&sortby=date&view=markup

This provides me one more incentive towards trying to get rid of the
vxl dependency.

It seems that, if done with care, mingw can create dll's that are
usable by MSVC (see
e.g.http://ffmpeg.arrozcru.org/wiki/index.php?title=MSVC ). Since
mingw does not necessarily require the dllimport/dllexport macro
(thanks to the export-all-symbols option), it could be a workaround
for us.

Did anyone try doing this (compile ITK with mingw, use the ITK
libraries in a project compiled with MSVC)?

Let me know if there is something that I am completely missing.

Regards,
Tom

On Mon, May 10, 2010 at 19:55, Tom Vercauteren <tom.vercauteren at m4x.org> wrote:
> Hi all,
>
> I am trying to help a fellow developer with building a project that
> uses ITK on windows. The project needs shared libraries because of a
> plugin mechanism.
>
> Hence ITK was built with BUILD_SHARED_LIBS=ON. Building our project
> fails at link time with the following error message:
>  ITKNrrdIO.lib(miscAir.obj) : error LNK2005: _itk_airFree already
> defined in mydll.lib(mydll.dll)
>  fatal error LNK1169: one or more multiply defined symbols found
>
> This arises each time we build an executable X that links with ITK and
> with another shared libray A that also links with ITK.
>
> I have filled a bug report here:
>  http://www.itk.org/Bug/view.php?id=10699
>
> Does anyone have a fix or a work-around for this problem?
>
> Apparently, the same problem has been in ITK for a while but was
> appearing with different symbols but my fellow developer apparently
> managed to work-around it previously by carefully picking when to link
> with what. I guess that this was only due to the fact that we were
> never in a more complex scenario that we now see:
>  X links with A and B. Both A and B link with some ITK library.
>
> A wild guess from my part would be that this could be related to the
> ITK_EXPORT macro. My basic understanding (I am not a regular windows
> developer) is that visual c++ requires one specific export/import
> macro per dll. ITK only uses ITKCommon_EXPORT and goes away with it by
> only building one shared library (ITKCommon.dll) while the other are
> built as static ones. This looks a bit weird to me. Could someone
> explain me the rationale of this approach?
>
> Cheers,
> Tom
>


More information about the Insight-developers mailing list