Compiling on M1 Macbook

Hi,

I’ve recently started Lazy Foo’s SDL tutorial and get the following errors when trying compile my test program. I’m on a M1 chip Macbook and suspect it has to do with that since many of the errors mention replacing ia32 with arm. As I’m new to SDL I’m not sure how to fix this on my end.

I’ve copied SDL2.framework into /Library/Frameworks and I’ve been compiling with g++ -l SDL2 test.cpp. Any guidance is appreciated!

In file included from /usr/local/include/SDL2/SDL.h:38:  
In file included from /usr/local/include/SDL2/SDL_cpuinfo.h:86:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/immintrin.h:14:
/Library/Developer/CommandLineTools/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();
    ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/math.h:647:12: note: '__builtin_isless' declared here
    return isless(__lcpp_x, __lcpp_y);
           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:545:22: note: expanded from macro 'isless'
#define isless(x, y) __builtin_isless((x),(y))
                     ^
In file included from test.cpp:1:
In file included from /usr/local/include/SDL2/SDL.h:38:
In file included from /usr/local/include/SDL2/SDL_cpuinfo.h:86:
In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/immintrin.h:14:
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:33:25: error: too few arguments to function call, expected 2,
      have 0
    __builtin_ia32_emms();
                        ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:50:19: error: use of undeclared identifier
      '__builtin_ia32_vec_init_v2si'
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:67:12: error: use of undeclared identifier
      '__builtin_ia32_vec_ext_v2si'
    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
           ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:129:19: error: use of undeclared identifier
      '__builtin_ia32_packsswb'
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:159:19: error: use of undeclared identifier
      '__builtin_ia32_packssdw'
    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:189:19: error: use of undeclared identifier
      '__builtin_ia32_packuswb'
    return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:216:19: error: use of undeclared identifier
      '__builtin_ia32_punpckhbw'
    return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:239:19: error: use of undeclared identifier
      '__builtin_ia32_punpckhwd'
    return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:260:19: error: use of undeclared identifier
      '__builtin_ia32_punpckhdq'
    return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:287:19: error: use of undeclared identifier
      '__builtin_ia32_punpcklbw'
    return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:310:19: error: use of undeclared identifier
      '__builtin_ia32_punpcklwd'
    return (__m64)__builtin_ia32_punpcklwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:331:19: error: use of undeclared identifier
      '__builtin_ia32_punpckldq'
    return (__m64)__builtin_ia32_punpckldq((__v2si)__m1, (__v2si)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: error: use of undeclared identifier
      '__builtin_ia32_paddb'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: error: first argument of MTE builtin function must be a
      pointer ('__v8qi' (vector of 8 'char' values) invalid)
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^                    ~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:373:19: error: use of undeclared identifier
      '__builtin_ia32_paddw'; did you mean '__builtin_arm_addg'?
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:373:19: error: first argument of MTE builtin function must be a
      pointer ('__v4hi' (vector of 4 'short' values) invalid)
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^                    ~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/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/12.0.0/include/mmintrin.h:352:19: note: '__builtin_arm_addg' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/mmintrin.h:394:19: error: first argument of MTE builtin function must be a
      pointer ('__v2si' (vector of 2 'int' values) invalid)
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^                    ~~~~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.```

My guess is that existing SDL headers will try to include mmintrin.h which will not work on ARM CPUs. This might be true in the existing prebuilt frameworks…?

1 Like

Small update, I’m not too familiar with what I did exactly but building SDL from the source code instead of using the prebuilt framework fixed the issue. Thanks!

1 Like

I’m getting the same error on my M1 Mac mini. Unfortunately, building from source, both from the latest stable and latest commit, will produce the same error.

Is there a workaround?

I’ll try to test this on a M1 Mac Mini today; there was a bug open about this recently, but it might be unrelated. I’ll check.

1 Like