# Incomplete mangling of the GDCM OpenJPEG library

**URL:** https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334
**Category:** Engineering
**Created:** [October 5, 2018, 9:01am UTC](https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334 "2018-10-05T09:01:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![denis.p.shamonin](https://discourse.itk.org/user_avatar/discourse.itk.org/denis.p.shamonin/32/112_2.png) [@denis.p.shamonin](https://discourse.itk.org/u/denis.p.shamonin)
#### Post date: [October 5, 2018, 9:01am UTC](https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334/1 "2018-10-05T09:01:30Z")

</div>

I recently found that your mangling of the OpenJPEG is incomplete. There are two OpenJPEG libraries in ITK:

1. ITK\Modules\ThirdParty\OpenJPEG\src\openjpeg
2. ITK\Modules\ThirdParty\GDCM\src\gdcm\Utilities\gdcmopenjpeg\src\lib\openjp2

The first one is an older version of OpenJPEG and appears mangled correctly. The second one from GDCM does miss a lot of functions to be mangled. We are linking against our own production version of the OpenJPEG and getting the following link errors (below).

Could you please re-mangled this library for the next maintenance release (4.13.2) and ITK 5?

Here is the list of my linking errors:

```
itkgdcmopenjp2-4.13.lib(image.obj) : error LNK2005: opj_image_create0 already defined ...
itkgdcmopenjp2-4.13.lib(image.obj) : error LNK2005: opj_image_comp_header_update already defined ...
itkgdcmopenjp2-4.13.lib(image.obj) : error LNK2005: opj_copy_image_header already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_write_bytes_BE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_read_bytes_BE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_write_bytes_LE already defined ... 
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_read_bytes_LE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_write_double_LE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_write_double_BE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_read_double_LE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_read_double_BE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_read_float_LE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_read_float_BE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_write_float_LE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_write_float_BE already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_read_data already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_write_data already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_flush already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_skip already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_tell already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_get_number_byte_left already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_write_skip already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_read_skip already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_read_seek already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_write_seek already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_seek already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_has_seek already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_default_read already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_default_write already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_default_skip already defined ...
itkgdcmopenjp2-4.13.lib(cio.obj) : error LNK2005: opj_stream_default_seek already defined ...
```

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 6, 2018, 2:42pm UTC](https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334/2 "2018-10-06T14:42:16Z")

</div>

If I remember correctly, @mathieu.malaterre is the maintainer of GDCM.

Until mangling is updated, you can configure ITK to use system GDCM, which you compile yourself. And when configuring that, enable [`GDCM_USE_SYSTEM_OPENJPEG`](https://github.com/malaterre/GDCM/blob/f4c455a5103ee7e9c32c3f12632826cb3ab0a5e3/CMakeLists.txt#L357-L362) and point to your own version of OpenJPEG.

---

<div class="post-metadata">

### Author: ![denis.p.shamonin](https://discourse.itk.org/user_avatar/discourse.itk.org/denis.p.shamonin/32/112_2.png) [@denis.p.shamonin](https://discourse.itk.org/u/denis.p.shamonin)
#### Post date: [October 8, 2018, 2:50pm UTC](https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334/3 "2018-10-08T14:50:20Z")

</div>

I wonder if any particular reasons to have outdated version in ITK\src\Modules\ThirdParty\OpenJPEG? Should it be at least up to the GDCM version or latest 2.3.0? Then we could directly use it.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [October 8, 2018, 3:12pm UTC](https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334/4 "2018-10-08T15:12:40Z")

</div>

Updating the OpenJPEG version is a good idea, but it is unlikely to happen in the near future unless a patch is contributed; there are many other higher priority maintenance tasks.

When updated, it is best to start using the update third party Git subtree bash script:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/65153d3546bb0b6b153d53893dc82272f5a5fa71/Utilities/Maintenance/update-third-party.bash#L17-L45>

This greatly reduces the burden of future updates.

---

<div class="post-metadata">

### Author: ![Niels\_Dekker](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/9d8465/32.png) [@Niels\_Dekker](https://discourse.itk.org/u/Niels_Dekker)
#### Post date: [October 30, 2018, 12:15pm UTC](https://discourse.itk.org/t/incomplete-mangling-of-the-gdcm-openjpeg-library/1334/5 "2018-10-30T12:15:52Z")

</div>

@mathieu.malaterre, @matt.mccormick, @dzenanz Please review this patch, from me and @denis.p.shamonin: [COMP: Fixed GDCM OpenJPEG name mangling](http://review.source.kitware.com/#/c/23848/)

It would be great if this issue could still be fixed with ITK 5.0 😀
