Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Update ITK to v5.2.0 to fix error during OpenJPEG build #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yoda-vid
Copy link

@yoda-vid yoda-vid commented Apr 7, 2021

This ITK update fixes a build error I encountered on Windows using Microsoft Visual Studio 16.9.3. The error occurs while compiling OpenJPEG for ITK with this message (multiple times):

Y:\builds_se_win\build_se_py3.6.8\ITK\Modules\ThirdParty\OpenJPEG\src\openjpeg\opj_includes.h(106,35): error C2169: 'lr
intf': intrinsic function, cannot be defined [Y:\builds_se_win\build_se_py3.6.8\ITK-build\Modules\ThirdParty\OpenJPEG\s
rc\openjpeg\itkopenjpeg.vcxproj] [Y:\builds_se_win\build_se_py3.6.8\ITK.vcxproj]

This error appears to the be the same as the one fixed recently in ITK:
InsightSoftwareConsortium/ITK#1967
InsightSoftwareConsortium/ITK#2388

I do not know of a way to pull this fix into SimpleElastix other than to pull in a more recent ITK commit (if there's another way, please let me know!). I simply bumped the tag from v5.1rc02 to v5.2.0 since this appears to be the only tag currently with this fix. I also found this update in SimpleITK (SimpleITK/SimpleITK#1366), so feel free to ignore this PR if upstream SimpleITK will be pulled in anyway.

With this update, the ITK compilation completes. Note that I could not fully complete the SimpleElastix compilation until I also checked out the latest branch here, update-simpleitk, which I built on commit 175864a , to avoid an Elastix build error.

I also had to use the official Cmake (tested on the latest version, v3.20.0) rather than MSVC Cmake (tested on v3.19.20122902-MSVC_2) to avoid an error when configuring Eigen3, which may be related to these issues:
InsightSoftwareConsortium/ITK#1888
ANTsX/ANTsR#275

ITK fixed a critical build error when compiling OpenJPEG as reported here:
InsightSoftwareConsortium/ITK#1967

Update ITK to the current latest version, which includes this fix.
Copy link
Member

@N-Dekker N-Dekker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much David. Actually I just encountered the very same compilation error, this afternoon!

@kaspermarstal @ViktorvdValk Is it also fine to you to upgrade to ITK 5.2.0? And do you happen to know why the CI rejected this pull request?

N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Apr 7, 2021
ITK fixed a critical build error when compiling OpenJPEG as reported here, by spacelg:

"ITK failed to build due to error C2169: 'lrintf': intrinsic function, cannot be defined with MSVC on windows"
issue InsightSoftwareConsortium/ITK#1967

Update ITK to version 5.2.0 (whose release is about to be announced), which includes this fix.

Following pull request SuperElastix/SimpleElastix#425 by David Young (yoda-vid)
@N-Dekker
Copy link
Member

N-Dekker commented Apr 7, 2021

FYI, We're preparing to upgrade ITK for elastix as well: https://github.com/SuperElastix/elastix/tree/Upgrade-ITK-to-v5.2.0

@yoda-vid
Copy link
Author

yoda-vid commented Apr 8, 2021

Great! I hope this might be helpful at least for troubleshooting.

@N-Dekker
Copy link
Member

N-Dekker commented Apr 8, 2021

@yoda-vid For what it's worth, I reproduced the original compilation error at https://godbolt.org/z/rbnsxarYW

#include <math.h>
long lrintf(float) { return 0; }
int main() {}

Compiler command line: /Oi /Bv
(/Oi enables intrinsic functions.)

Output:

error C2169: 'lrintf': intrinsic function, cannot be defined

Compiler version:

C:\data\msvc\14.28.29914\bin\Hostx64\x64\cl.exe: Version 19.28.29914.0

@N-Dekker
Copy link
Member

N-Dekker commented Apr 8, 2021

For the record, the lrintf function from OpenJPEG was originally renamed to "opj_lrintf" by Matthieu Darbois (@mayeut), 26 July 2015, "Remove some warnings when building" uclouvain/openjpeg@c423cc8#diff-91c70438e617694516cb0ab60919517ff67034354cf73070cb243a7680411f89R126

https://github.com/uclouvain/openjpeg/blob/c423cc84e7be79051a7f9631fa26aa7d072361f2/src/lib/openjp2/opj_includes.h#L126

This commit is included with OpenJPEG tag v2.1.1

@yoda-vid
Copy link
Author

This is really cool, thanks for sleuthing that out! So from my understanding:

Seems to make sense now why my previous build of SimpleElastix (on commit 2a79d15) with Visual Studio 2019 (MSVC 14.22.27905) worked, whereas my recent build on the same commit did not on MSVC 14.28.29910.

@N-Dekker
Copy link
Member

  • OpenJPEG fixed this awhile back
  • ITK ships an older version of OpenJPEG that did not include this fix
  • The recent MSVC update now gives an error (eg as suggested in microsoft/vcpkg#16645 (comment))?
  • The ITK PR fixed this issue for their version

@yoda-vid Well summarized, David 😃 By the way, ITK's fix is not entirely complete, as it defines opj_lrintf for MSVC, but not for Clang and GCC. As I mentioned at InsightSoftwareConsortium/ITK#2388 (comment) But in practice it doesn't matter much, I guess, because ITK does not use opj_lrintf anyway 🤔

@yoda-vid
Copy link
Author

Good to know! At least we will have a place to start looking if the builds start to break on Clang or GCC.

@kaspermarstal
Copy link
Member

Great, thanks @yoda-vid! Could you make the PR against develop instead of master? Develop was just updated to SimpleITK v2.0.2 and I hope to merge into master soon. Better check these changes are compatible :)

@yoda-vid yoda-vid changed the base branch from master to develop April 15, 2021 01:48
yoda-vid added a commit to yoda-vid/SimpleElastix that referenced this pull request Apr 15, 2021
Change ITK to the current latest version, which includes this fix. Rebased to `develop` branch from PR SuperElastix#425 .
@yoda-vid yoda-vid changed the base branch from develop to master April 15, 2021 02:26
@yoda-vid
Copy link
Author

Thanks, @kaspermarstal ! I made a new PR on develop: #428 . Initially I tried to use the GitHub function to change the PR base here, but it didn't seem to update the base when I pulled it, so I just created a new PR instead.

N-Dekker added a commit to SuperElastix/elastix that referenced this pull request May 29, 2021
ITK fixed a critical build error when compiling OpenJPEG as reported here, by spacelg:

"ITK failed to build due to error C2169: 'lrintf': intrinsic function, cannot be defined with MSVC on windows"
issue InsightSoftwareConsortium/ITK#1967

Update ITK to version 5.2.0 (whose release is about to be announced), which includes this fix.

Following pull request SuperElastix/SimpleElastix#425 by David Young (yoda-vid)
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request May 29, 2021
Upgraded to ITK version 5.2.0, which was released on May 28, 2021.

ITK 5.2.0 fixed a critical issue, with commit  InsightSoftwareConsortium/ITK@7cebc26 "COMP: Fix OpenJPEG build error with Visual Studio 16.9", by James Butler (jamesobutler) and spacelg

Following pull request SuperElastix/SimpleElastix#425 and SuperElastix/SimpleElastix#428 by David Young (yoda-vid)

Obviously, ITK 5.2.0 has many other improvements: https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.2.0
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request May 31, 2021
Upgraded to ITK version 5.2.0, which was released on May 28, 2021.

ITK 5.2.0 fixed a critical issue, with commit  InsightSoftwareConsortium/ITK@7cebc26 "COMP: Fix OpenJPEG build error with Visual Studio 16.9", by James Butler (jamesobutler) and spacelg

Following pull request SuperElastix/SimpleElastix#425 and SuperElastix/SimpleElastix#428 by David Young (yoda-vid)

Obviously, ITK 5.2.0 has many other improvements: https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.2.0
@davidweioct
Copy link

Hi, not sure if this issue has solved or not for simpleElastix. I tried with both the master branch and the develop branch over the weekend, but the issue still exists. error C2169 repeated 19 times. Is there a solution? An old version (early 2020) of the package would also work for me. Is there a way to clone that? Thanks a million!

@N-Dekker
Copy link
Member

@davidweioct

Hi, not sure if this issue has solved or not for simpleElastix. I tried with both the master branch and the develop branch over the weekend, but the issue still exists. error C2169 repeated 19 times.

As a quick-fix you may simply remove both static lrintf function definitions from you copy of ITK/Modules/ThirdParty/OpenJPEG/src/openjpeg/opj_includes.h The function isn't being called by anyway, neither by ITK nor by elastix.

HTH, Niels

@yoda-vid
Copy link
Author

As a quick-fix you may simply remove both static lrintf function definitions

This is good to know, thanks @N-Dekker!

Just to add on, the build is working in PR #428 on develop (at least at the time of posting). I've checked it out locally by:

git fetch origin pull/428/head:test_pr428
git checkout test_pr428

(Assuming origin points to the main repo.)

@davidweioct
Copy link

Thank you both @N-Dekker @yoda-vid .

I tried by commenting out those lines, and this works for me without any error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants