zoglauer / megalib

MEGAlib - the Medium-Energy Gamma-ray Astronomy library
http://megalibtoolkit.com
Other
41 stars 32 forks source link

ROOT compiled as x86_64 instead of arm64 on M2 Mac #85

Open gmitch3088 opened 11 months ago

gmitch3088 commented 11 months ago

Hi Andreas,

I have been using MEGAlib for many years (I think since ~2017). It is a really wonderful toolkit! I am running into a problem building the most recent version. I have pasted my error message below. For reference, I am using an M2 Pro Mac on MacOS Ventura. Please let me know if there is any other information I can provide to help!

Thank you! Grant Mitchell

Linking geomega ... ld: warning: duplicate -rpath '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib' ignored ld: warning: -bind_at_load is deprecated on macOS ld: warning: ignoring duplicate libraries: '-lCore', '-lGpad', '-lGraf', '-lGraf3d', '-lHist', '-lImt', '-lMathCore', '-lMatrix', '-lMultiProc', '-lNet', '-lPhysics', '-lPostscript', '-lRIO', '-lROOTDataFrame', '-lROOTVecOps', '-lRint', '-lThread', '-lTree', '-lTreePlayer', '-ldl', '-lm', '-lpthread' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libGui.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libCore.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libGraf.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libHist.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libNet.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libImt.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libROOTVecOps.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libTree.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libGpad.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libRIO.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libPostscript.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libTreePlayer.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libGraf3d.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libMatrix.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libRint.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libThread.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libMathCore.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libPhysics.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libMultiProc.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libROOTDataFrame.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libGeom.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libMinuit.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libTMVA.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/Users/jgmitch3/MEGAlib/external/root_v6.28.08/lib/libSpectrum.6.28.08.so': found architecture 'x86_64', required architecture 'arm64' ld: Undefined symbols: TApplication::TApplication(char const, int, char, void, int), referenced from: _main in MGeomegaMain.o TVersionCheck::TVersionCheck(int), referenced from: GLOBALsub_I_MGeomegaMain.cxx in MGeomegaMain.o TObject::operator delete(void), referenced from: _main in MGeomegaMain.o TStorage::ObjectAlloc(unsigned long), referenced from: _main in MGeomegaMain.o clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: ** [/Users/jgmitch3/MEGAlib/bin/geomega] Error 1 make[1]: [geo] Error 2 make: *** [geo] Error 2

zoglauer commented 11 months ago

Hi Mitchell,

This: found architecture 'x86_64', required architecture 'arm64' says that ROOT has been compiled for x86_64, i.e. INTEL CPUs, and you try to compile MEGAlib itself for ARM, i.e. your M2. Those two cannot work together.

Did you use the MEGAlib setup script to compile ROOT? Because normally the MEGAlib script also compiles ROOT for ARM.

If you compiled it with the setup script, can you attach the following file: external/root_v6.28.08/BuildLogROOT.txt

Best, Andreas

gmitch3088 commented 11 months ago

Attached is the RootBuildLog.txt file. I indeed used the MEGAlib setup script to compile ROOT. RootBuildLog.txt

zoglauer commented 11 months ago

I think this might be a cmake issue when building ROOT and not a MEGAlib issue:

In your build log you have: ... -- Found a macOS system 13.5 -- Found an x86_64 system -- Performing Test GLIBCXX_USE_CXX11_ABI -- Performing Test GLIBCXX_USE_CXX11_ABI - Failed -- ROOT Platform: macosx -- ROOT Compiler: AppleClang 15.0.0.15000040 -- ROOT Processor: x86_64 -- ROOT Architecture: macosx64 ... System Darwin-22.6.0 Processor 12 core Apple M2 Pro (x86_64) ...

Thus you have an M2, and cmake things it should compile ROOT for x86_64, i.e. INTEL and not for arm64 .

Which version of cmake are you using? I have cmake version 3.24.4 installed via macports on an M1, and there everything seems to work.

My build log says: -- Found a macOS system 13.5 -- Found an AArch64 system -- Performing Test GLIBCXX_USE_CXX11_ABI -- Performing Test GLIBCXX_USE_CXX11_ABI - Failed -- ROOT Platform: macosx -- ROOT Compiler: AppleClang 15.0.0.15000040 -- ROOT Processor: arm64 -- ROOT Architecture: macosxarm64 Thus it properly determined that I am running on an ARM processor.

Another guess might be that you have Rosetta 2 running and that influences cmakes decision to use x86_64 instead of arm64.

gmitch3088 commented 11 months ago

I'm using cmake 3.27.4

I'll look around and see if there is some setting that is causing this issue.

zoglauer commented 11 months ago

I am trying to reproduce the issue. How did you install cmake? Direct download, macports, home-brew, conda?

gmitch3088 commented 11 months ago

I installed it using home-brew. Just to update, I tried going directly into the build-root.sh file and adding CONFIGUREOPTIONS+=" -DCMAKE_OSX_ARCHITECTURES=arm64" but this still did not build using arm64

zoglauer commented 11 months ago

Thanks.

Can you check this link, in case you run the setup with Rosetta which would lead to it seeing x86_64? https://stackoverflow.com/questions/76057246/why-does-cmake-insist-that-the-processor-used-is-x86-64-when-it-is-actually-arm6

gmitch3088 commented 11 months ago

There were some helpful hints in there! So, first I was running Homebrew still in x86_64 mode so I switched that to arm64. I tried building MEGAlib again and got a different set of errors (so making progress). Do you see anything in here that is helpful? I also attached the root build log.

-- clad build command succeeded. See also /Users/jgmitch3/MEGAlib/external/root_v6.28.08/root_v6.28.08-build/interpreter/cling/tools/plugins/clad/clad-prefix/src/clad-stamp/clad-build-.log [ 77%] Performing install step for 'clad' -- clad install command succeeded. See also /Users/jgmitch3/MEGAlib/external/root_v6.28.08/root_v6.28.08-build/interpreter/cling/tools/plugins/clad/clad-prefix/src/clad-stamp/clad-install-.log [ 77%] Completed 'clad' [ 77%] Built target clad [ 77%] Linking CXX shared library ../../../lib/libCling.so [ 77%] Built target Cling [ 77%] Building CXX object core/CMakeFiles/GCore.dir/GCore.cxx.o [ 77%] Built target GCore [ 77%] Linking CXX shared library ../lib/libCore.so ld: warning: ignoring file '/usr/local/Cellar/lz4/1.9.4/lib/liblz4.1.9.4.dylib': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/usr/local/Cellar/xxhash/0.8.2/lib/libxxhash.0.8.2.dylib': found architecture 'x86_64', required architecture 'arm64' ld: warning: ignoring file '/usr/local/Cellar/zstd/1.5.5/lib/libzstd.1.5.5.dylib': found architecture 'x86_64', required architecture 'arm64' ld: Undefined symbols: _LZ4_compress_HC, referenced from: _RzipLZ4 in ZipLZ4.cxx.o _LZ4_compress_default, referenced from: _RzipLZ4 in ZipLZ4.cxx.o _LZ4_decompress_safe, referenced from: _R__unzipLZ4 in ZipLZ4.cxx.o _LZ4_versionNumber, referenced from: _RzipLZ4 in ZipLZ4.cxx.o _RunzipLZ4 in ZipLZ4.cxx.o _XXH64, referenced from: _RzipLZ4 in ZipLZ4.cxx.o _RunzipLZ4 in ZipLZ4.cxx.o _XXH64_canonicalFromHash, referenced from: _R__zipLZ4 in ZipLZ4.cxx.o _XXH64_hashFromCanonical, referenced from: _RunzipLZ4 in ZipLZ4.cxx.o _ZSTD_compressCCtx, referenced from: _RzipZSTD in ZipZSTD.cxx.o _ZSTD_createCCtx, referenced from: _R__zipZSTD in ZipZSTD.cxx.o _ZSTD_createDCtx, referenced from: _RunzipZSTD in ZipZSTD.cxx.o _ZSTD_decompressDCtx, referenced from: _RunzipZSTD in ZipZSTD.cxx.o _ZSTD_freeCCtx, referenced from: _R__zipZSTD in ZipZSTD.cxx.o _RzipZSTD in ZipZSTD.cxx.o _ZSTD_freeDCtx, referenced from: _RunzipZSTD in ZipZSTD.cxx.o _R__unzipZSTD in ZipZSTD.cxx.o _ZSTD_getErrorName, referenced from: _RzipZSTD in ZipZSTD.cxx.o _RunzipZSTD in ZipZSTD.cxx.o _ZSTD_isError, referenced from: _R__zipZSTD in ZipZSTD.cxx.o _RunzipZSTD in ZipZSTD.cxx.o _ZSTD_versionNumber, referenced from: _R__unzipZSTD in ZipZSTD.cxx.o clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: [lib/libCore.6.28.08.so] Error 1 make[1]: [core/CMakeFiles/Core.dir/all] E RootBuildLog.txt rror 2 make: *** [all] Error 2 ERROR: Something went wrong while compiling ROOT!

zoglauer commented 11 months ago

I think it is still the same general issue. For example: ld: warning: ignoring file '/usr/local/Cellar/lz4/1.9.4/lib/liblz4.1.9.4.dylib': found architecture 'x86_64', required architecture 'arm64' ld: Undefined symbols: _LZ4_compress_HC, referenced from: _R__zipLZ4 in ZipLZ4.cxx.o

The lz4 library from home-brew is still x86_64 but needs to be arm64 for it to be used.

gmitch3088 commented 11 months ago

I think I have MEGAlib working now. I had to re-install a variety of libraries from home-brew. The only error I got that was not solved by installing new versions of the libraries was solved by including CONFIGUREOPTIONS+=" -Dbuiltin_glew=ON" in build-root.sh

I'm not sure if that is something that would be useful to anyone else but I wanted to let you know just in case. Thank you again for all of your help and for making MEGAlib available to the public!

zoglauer commented 11 months ago

Great. Thanks!

What error message did you get which required -Dbuiltin_glew=ON?

Thanks, Andreas

gmitch3088 commented 11 months ago

Here was the error:

-- Found GLEW: /usr/local/lib/cmake/glew/glew-config.cmake
CMake Error at cmake/modules/SearchInstalledSoftware.cmake:614 (message): Please enable builtin Glew due bug in latest CMake (use cmake option -Dbuiltin_glew=ON). Call Stack (most recent call first): CMakeLists.txt:254 (include)

-- Configuring incomplete, errors occurred! ERROR: Something went wrong configuring (cmake'ing) ROOT!