GLVis / glvis

Lightweight OpenGL tool for accurate and flexible finite element visualization
http://glvis.org
BSD 3-Clause "New" or "Revised" License
251 stars 51 forks source link

Can't build on M1 Apple Silicon version! #224

Closed supriome closed 1 year ago

supriome commented 2 years ago

When build on macOS m1 with command make MFEM_DIR=../mfem-4.4 -j, there some problem.

fatal error: too many errors emitted, stopping now [-ferror-limit=]
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/mmintrin.h:394:19: error: use of undeclared identifier '__builtin_ia32_paddd'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/mmintrin.h:394:19: error: use of undeclared identifier '__builtin_ia32_paddd'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);

Seems that clang++ version not support.

tzanio commented 2 years ago

Hi @supriome,

Unfortunately I don't have access to an M1 mac to try to reproduce this, but looking at the error this doesn't seem to be an issue inside GLVis.

I know other folks have gotten MFEM to work on M1 macs, see https://github.com/mfem/mfem/pull/2273.

Does your MFEM build works, e.g. does "make test" work there?

tzanio commented 2 years ago

ping: @matthiasdiener and @samuelpmishLLNL, in case you can help.

matthiasdiener commented 2 years ago

This build script for mfem works for Mac M1: https://github.com/conda-forge/mfem-feedstock/blob/main/recipe/build.sh

Have you run make config when building mfem? It looks like it is trying to compile for x86 (see e.g. the warning for __builtin_ia32_paddd)

congunter commented 2 years ago

@supriome I got the same error message, where MFEM would compile but glvis would not. Tried all of the solutions posted, as well as confirming homebrew and command line tools were up to date. The MFEM build was confirmed to be compiled for arm64. It seems to be a linking issue with clang via apple command line tools. The line where compilation fails on my M1 Mac is:

> g++ -O3 -std=c++11 -I../mfem-4.4 -DGLVIS_MULTISAMPLE=4 -DGLVIS_MS_LINEWIDTH=1.0 -DGLVIS_OGL3 -DGLVIS_USE_LOGO -I/opt/X11/include/freetype2 -I/usr/local/include -I/usr/local/include -I/opt/homebrew/include -DGLVIS_USE_LIBPNG -o lib/aux_vis.o -c lib/aux_vis.cpp

It seems that when using make or gmake, there is an issue with clang trying to compile with x86 for a few of the libraries, starting with libGL. Instead of compiling via llvm installed through homebrew, it tries to install with the apple command line version of clang. Here is the filepath for the first error thrown:

In file included from lib/gl/renderer.cpp:12:
In file included from lib/gl/renderer.hpp:20:
In file included from lib/gl/platform_gl.hpp:17:
In file included from /usr/local/include/SDL2/SDL.h:38:
In file included from /usr/local/include/SDL2/SDL_cpuinfo.h:102:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/immintrin.h:13:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include/x86gprintrin.h:15:

I tried using:

> echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc

which didn't fix the issue.

To fix this, I edited the makefile search path lines for glew, SDL2, gym, and OpenGL (lines 166, 172, 177, 178, and 182) to force compilation via llvm installed via homebrew:

166:      GLEW_SEARCH_PATHS =  $(BREW_PREFIX) $(abspath ../glew)

172:      SDL_SEARCH_PATHS :=  $(BREW_PREFIX) $(abspath ../SDL2)

177:      GLM_SEARCH_PATHS = \  

178:      $(if $(BREW_PREFIX), $(BREW_PREFIX)/include) $(abspath ../glm)

182:     OPENGL_SEARCH_PATHS = $(BREW_PREFIX) /usr /usr/local /opt/local

Compiled MFEM with:

> gmake serial -j 4

Compiled with GLVIS with:

> gmake MFEM_DIR=../mfem-4.4 -j 4

This is probably just a quick and dirty way to fix it, but it worked for me. I have tested and verified functionality with the MFEM examples. Also I did not try with cmake, so that might work.

tzanio commented 2 years ago

Thank you @congunter

TobiasDuswald commented 2 years ago

Hi all,

I'm running MFEM and GLVis on my M1 for a year and I never had any issues. I've tried different commits of both software packages and it always worked fine. Both, MFEM and GLVis are in my home folder, e.g. ~/mfem and ~/glvis. I compile both packages with cmake, e.g.

cd ~/mfem
mkdir build
cd build
cmake ..
make -j8

and

cd ~/glvis
mkdir build
cd build
cmake ..
make -j8

Note that GLVis requires a few external dependencies that can be installed via brew. The following list might not be exhaustive, but I believe I had to install the following packages:

But Cmake should guide you through this process of installing missing dependencies (if there are any). This works on M1 without any problems. To run GLVis, I execute

glvis/build/glvis

in my home folder. Executing an MFEM example such as ex16 should then be able to communicate with the running GLVis server. E.g. try

cd ~/mfem/build/examples
make ex16
./ex16

Hope that helps, good luck!