Mercury-Language / mercury

The Mercury logic programming system.
Other
904 stars 54 forks source link

_MR_atomic_sub_int symbol not found on macOS #110

Open poldy opened 1 year ago

poldy commented 1 year ago

The full error message is:

dyld[47054]: symbol not found in flat namespace '_MR_atomic_sub_int'

I installed Mercury from homebrew using brew install mercury. This is on an M1 Mac running the latest Ventura. A sequential "hello world" program compiles and runs no problem. And indeed, when I compile the Dining Philosophers sample code with either --parallel or --grade hlc.par.gc it compiles ok, but when I run it gives the above error message.

juliensf commented 1 year ago

I assume that you are using clang as the C compiler here. The problem is simply that there is not a definition of MR_atomic_sub_int for clang on Aarch64 based systems in the runtime; we will need to add one. (There is a generic definition for GCC which should work on M1 based systems, although I've not tested that myself, so installing GCC via homebrew and using that may be an option.)

poldy commented 1 year ago

Yes, I'm using clang.

I added the bare minimum of code to get the build to complete. It could be quite a lot of work, but there are some nice features that Mercury could make use of if you introduced a minimum required version of C11.

juliensf commented 1 year ago

Requiring the use of C11 is not an option in the short to medium term. MSVC only just gained some initial experimental support for C11/C17 style atomics (and I gather even that is not complete). It would make sense for us to starting C11 atomics on platforms where they are supported (i.e. in preference to the inline assembly).

poldy commented 1 year ago

I logged PR #114 in an attempt to do this. Feel free to review ...