rordenlab / dcm2niix

dcm2nii DICOM to NIfTI converter: compiled versions available from NITRC
https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage
Other
899 stars 229 forks source link

fatal error: "algorithm" file not found - build fails on MacOS 14.7 with Clang 16 #868

Closed pmolfese closed 1 month ago

pmolfese commented 1 month ago

Describe the bug

Build fails with AppleClang 16.0.0.16000026 on macOS 14.7. Algorithm library not found. Was not an issue prior to updating to 14.7.

dcm2niix/console/nii_dicom.cpp:41:10: fatal error: 'algorithm' file not found
make[5]: *** [CMakeFiles/dcm2niix.dir/nii_dicom.cpp.o] Error 1
make[4]: *** [CMakeFiles/dcm2niix.dir/all] Error 2
make[3]: *** [all] Error 2
make[2]: *** [console-prefix/src/console-stamp/console-build] Error 2
make[1]: *** [CMakeFiles/console.dir/all] Error 2
make: *** [all] Error 2

To reproduce

Steps to reproduce the behavior:

1. git clone https://github.com/rordenlab/dcm2niix
2. cd dcm2niix
3. mkdir build && cd build
4. cmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON ..
5. make

Also fails using development branch:

git clone --branch development https://github.com/rordenlab/dcm2niix.git
cd dcm2niix/console
make
./dcm2niix ....

Expected behavior

Compiler should correctly find

Output log

make
[  4%] Performing update step for 'openjpeg'
[  8%] No patch step for 'openjpeg'
[ 12%] Performing configure step for 'openjpeg'
Not searching for unused variables given on the command line.
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: ~/dcm2niix/build/openjpeg-build
[ 16%] Performing build step for 'openjpeg'
[100%] Built target openjp2
[ 20%] Performing install step for 'openjpeg'
[100%] Built target openjp2
Install the project...
-- Install configuration: "Release"
-- Up-to-date: ~/dcm2niix/build/lib/openjpeg-2.1/OpenJPEGTargets.cmake
-- Up-to-date: ~/dcm2niix/build/lib/openjpeg-2.1/OpenJPEGTargets-release.cmake
-- Up-to-date: ~/dcm2niix/build/lib/openjpeg-2.1/OpenJPEGConfig.cmake
-- Up-to-date: ~/dcm2niix/build/lib/pkgconfig/libopenjp2.pc
-- Up-to-date: ~/dcm2niix/build/include/openjpeg-2.1/opj_config.h
-- Installing: ~/dcm2niix/build/lib/libopenjp2.a
-- Up-to-date: ~/dcm2niix/build/include/openjpeg-2.1/openjpeg.h
-- Up-to-date: ~/dcm2niix/build/include/openjpeg-2.1/opj_stdint.h
[ 25%] Completed 'openjpeg'
[ 33%] Built target openjpeg
[ 37%] Performing update step for 'zlib'
[ 41%] No patch step for 'zlib'
[ 45%] Performing configure step for 'zlib'
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: ~/dcm2niix/build/cloudflare-zlib-build
[ 50%] Performing build step for 'zlib'
[100%] Built target zlib
[ 54%] Performing install step for 'zlib'
[100%] Built target zlib
Install the project...
-- Install configuration: "Release"
-- Installing: ~/dcm2niix/build/lib/libz.a
-- Up-to-date: ~/dcm2niix/build/include/zconf.h
-- Up-to-date: ~/dcm2niix/build/include/zlib.h
-- Up-to-date: ~/dcm2niix/build/share/man/man3/zlib.3
-- Up-to-date: ~/dcm2niix/build/lib/pkgconfig/zlib.pc
[ 58%] Completed 'zlib'
[ 66%] Built target zlib
[ 70%] Performing configure step for 'console'
Not searching for unused variables given on the command line.
-- Set BUILD_DCM2NIIXFSLIB to OFF since USE_TURBOJPEG/USE_JASPER/USE_OPENJPEG is ON.
--   Adding Apple plist
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: ~/dcm2niix/build/console-build
[ 75%] Performing build step for 'console'
[  6%] Building CXX object CMakeFiles/dcm2niix.dir/nii_dicom.cpp.o
~/dcm2niix/console/nii_dicom.cpp:41:10: fatal error: 'algorithm' file not found
make[5]: *** [CMakeFiles/dcm2niix.dir/nii_dicom.cpp.o] Error 1
make[4]: *** [CMakeFiles/dcm2niix.dir/all] Error 2
make[3]: *** [all] Error 2
make[2]: *** [console-prefix/src/console-stamp/console-build] Error 2
make[1]: *** [CMakeFiles/console.dir/all] Error 2
make: *** [all] Error 2

Version

Please report the complete version string:

Troubleshooting

Please try the following steps to resolve your issue:

git clone --branch development https://github.com/rordenlab/dcm2niix.git
cd dcm2niix/console
make
./dcm2niix ....
pmolfese commented 1 month ago

The issue is resolved if I use g++ from gcc. Seems like Clang can't find parts of the standard library.

neurolabusc commented 1 month ago

Unable to replicate. My best guess is you have not accepted the new Apple developer agreement. The easiest way to do this after you upgrade is to open up the Xcode application - it should demand that you sign off on the new agreements. I think you can also do this online with your Apple Developer accound.

git clone --branch development git@github.com:rordenlab/dcm2niix.git
cd dcm2niix
mkdir build
cd build
cmake -DZLIB_IMPLEMENTATION=Cloudflare -DUSE_JPEGLS=ON -DUSE_OPENJPEG=ON ..
make
./bin/dcm2niix
Chris Rorden's dcm2niiX version v1.0.20241001  (JP2:OpenJPEG) (JP-LS:CharLS) Clang16.0.0 ARM (64-bit MacOS)
...
clang --version
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
sw_vers
ProductName:        macOS
ProductVersion:     14.7
BuildVersion:       23H124
pmolfese commented 1 month ago

The developer agreement was already accepted. I wiped the CommandLineTools and reinstalled:

sudo rm -rf /Library/Developer/CommandLineTools
Xcode-select --install 

This fixed the issue.