Compile failure on Mac OSX M1 arm64

Has anyone successfully compiled the server on an M1 Laptop for an M1 laptop?

When I run the cmake command on an M1 laptop:

cmake -GXcode -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 -DSTATIC_BUILD=ON -DSTANDALONE_BUILD=ON -DALLOW_DOWNLOADS=ON …/OrthancServer

OR

cmake -GXcode -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DSTATIC_BUILD=ON -DSTANDALONE_BUILD=ON -DALLOW_DOWNLOADS=ON …/OrthancServer

I get an error that seems like Xcode is running a test for a webassembly target on an x86

Here is one of the errors that I get:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target arm64-apple-macos10.9 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR="Release" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/Release/include -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Release/cmTC_1c6c0.build/DerivedSources-normal/arm64 -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Release/cmTC_1c6c0.build/DerivedSources/arm64 -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Release/cmTC_1c6c0.build/DerivedSources -F/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/Release -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6//config/include -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/ofstd/include -I/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/ofstd/libsrc -MMD -MT dependencies -MF /Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Release/cmTC_1c6c0.build/Objects-normal/arm64/arith.d --serialize-diagnostics /Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Release/cmTC_1c6c0.build/Objects-normal/arm64/arith.dia -c /Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/config/tests/arith.cc -o /Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/CMakeTmp/Arith/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Release/cmTC_1c6c0.build/Objects-normal/arm64/arith.o

In file included from
/Users/jmurray/code/orthanc/Build/dcmtk-3.6.6/config/tests/arith.cc:45:

In file included from
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/xmmintrin.h:13:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include/mmintrin.h:33:5:
error: use of undeclared identifier ‘__builtin_ia32_emms’; did you mean
‘__builtin_isless’?

__builtin_ia32_emms();

I just downloaded the compiled one from Osimis and it works no problem.

Thank you, Bryan! I tried to load the binary image, but I did not understand how the command file worked. After about 10 overrides of non-Apple Store files, I got the binary version of the server to work. Thank you!!!

I am curious to know if there is some special command to compile the code on an M1 or if it was cross-compiled from an x86 mac.

thank you!

john

Hello,

This compilation error means that either DCMTK doesn’t support M1 (unlikely), or that the following files must be adapted in the source code of Orthanc (more probable):
https://hg.orthanc-server.com/orthanc/file/default/OrthancFramework/Resources/CMake/DcmtkConfiguration.cmake

https://hg.orthanc-server.com/orthanc/file/default/OrthancFramework/Resources/CMake/DcmtkConfigurationStatic-3.6.6.cmake

Similar compilation errors have been reported for other software, for instance:
https://github.com/emscripten-core/emscripten-fastcomp-clang/issues/29

Unfortunately, I don’t have access to such an Apple computer, so I can’t provide any fix by myself.

To answer the second part of your question, the Osimis binary package is built on a x86 MacMini from 2014. Full info:

$ system_profiler SPSoftwareDataType
Software:

System Software Overview:

System Version: OS X 10.9.5 (13F1911)
Kernel Version: Darwin 13.4.0

Sébastien-

I have an M1 Mac so can help to troubleshoot. I did try to install dmctk using home brew a week or so back and it didn’t compile either.

Are there any pointers you can give so I can look into it?

James

Binary Logo

James Manners • Director
Suite 3, Level 2, 10 Queens Road, Melbourne, Victoria 3004, Australia

T: 03 9017 5230 M: 0422 973 235 E: james@binary.com.au W: binary.com.au

Hello James,

Thanks for your feedback! The first thing to try would indeed be to compile DCMTK 3.6.6 from source (using CMake) on M1 Mac, without even considering Orthanc.

If the compilation doesn’t succeed, this should be reported to the DCMTK team:
https://forum.dcmtk.org/

Sébastien-

Hi Sebastien,

I had a quick look on the DCMTK Issue Tracker and this issue is open regarding compilation on a Mac M1 (ARM) chip https://support.dcmtk.org/redmine/issues/957

So it looks like there are issues with DCMTK compiling on an M1.

HTH

James

Thank you to all. I am using the cross-compiled binary. I appreciate the investigation.

We can let this one go for now.

john

Hi,

Here are 2 fixes which seems to solve the Apple M1 build issues:
https://hg.orthanc-server.com/orthanc/rev/1b6b88f017b9
https://hg.orthanc-server.com/orthanc/rev/3c3bb0181e96

At least, I’ve been able to produce a universal binary on an Intel Mac but I have not been able to run it on a M1 processor (because I don’t have any :slight_smile: ). Any feedback is welcome.

HTH

Alain.

Just for information,
In case you need a M1 environement to code / test

You can have a M1 instance for few hours in some cloud providers such as scaleway : https://www.scaleway.com/en/hello-m1

This way no need to pay for overpriced mac products ^^

Salim