Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mame: Compilation error on older MacOS/Xcode releases, for file 'src/osd/modules/file/posixfile.cpp' #7536

Closed
mascguy opened this issue Dec 9, 2020 · 0 comments

Comments

@mascguy
Copy link

mascguy commented Dec 9, 2020

Mame 0.226 fails to build on MacOS 10.8 and Xcode 5.x, due to compilation errors in file src/osd/modules/files/posixfile.cpp.

Here's one example:

In file included from ../../../../../src/osd/modules/file/posixfile.cpp:41:
In file included from ../../../../../src/osd/modules/file/posixfile.h:12:
In file included from ../../../../../src/osd/osdcore.h:17:
In file included from ../../../../../src/lib/util/strformat.h:174:
In file included from ../../../../../src/lib/util/vecstream.h:25:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/istream:163:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/ostream:140:
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/locale:1455:16: error: use of undeclared identifier 'snprintf_l'; did you mean 'vswprintf_l'?
    int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
               ^

Root cause is the preprocessor logic within C header file /usr/include/xlocale/_stdio.h, determining whether additional stdio functions are defined. One of those being snprintf_l().

Findings:

  • In later MacOS/Xcode releases, the logic is #if __DARWIN_C_LEVEL >= 200112L || defined(__cplusplus). The latter condition ensures we don't have to worry about __DARWIN_C_LEVEL.
  • But under MacOS 10.8 and Xcode 5.x, the logic is simply #if __DARWIN_C_LEVEL >= 200112L, with no awareness of C++ code. This breaks the Mame build.

The fix is easy: Define _DARWIN_C_SOURCE in posixfile.cpp, before including any library headers:

--- src/osd/modules/file/posixfile.cpp	2020-12-08 16:14:00.000000000 -0500
+++ src/osd/modules/file/posixfile.cpp	2020-12-08 16:15:00.000000000 -0500
@@ -37,6 +37,11 @@
 #endif
 #endif

+// Fix for MacOS compilation errors
+#if defined(__APPLE__) && !defined(_DARWIN_C_SOURCE)
+#define _DARWIN_C_SOURCE
+#endif
+
 // MAME headers
 #include "posixfile.h"
 #include "unicode.h"

I'll submit a pull request with the requested change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants