Skip to content

fix: modern clang compatibility (c++03, fgets, tolower, macOS ld) - #32

Closed
bqw371 wants to merge 1 commit into
libretro:masterfrom
bqw371:fix/modern-clang-compilation
Closed

fix: modern clang compatibility (c++03, fgets, tolower, macOS ld)#32
bqw371 wants to merge 1 commit into
libretro:masterfrom
bqw371:fix/modern-clang-compilation

Conversation

@bqw371

@bqw371 bqw371 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

Three fixes required to build libretro-fceux with modern clang (Apple clang 15+ / LLVM 16+) on macOS arm64 or cross-compiling for arm64-Linux. All three are straightforward correctness fixes that silence hard errors (not just warnings).

1. src-fceux/cheat.cppfgets() pointer vs int comparison

fgets() returns char*, so comparing with >0 is a pointer-to-integer comparison, which is an error in modern clang (-Werror or by default in strict mode).

// before
while(fgets(linebuf,2048,fp)>0)
// after  
while(fgets(linebuf,2048,fp))

2. src-fceux/utils/xstring.cpp — conflicting tolower declaration

The file declares its own extern "C" int tolower(int) which conflicts with <cctype>'s tolower. Modern clang rejects conflicting linkage specifications.

// before: hand-rolled extern "C" declaration
// after: #include <ctype.h>

3. Makefile.libretro-fceux — C++03 mode + macOS linker flag

  • Added -std=c++03 -Wno-narrowing -Wno-reserved-user-defined-literal to CXXFLAGS: required because the source uses C++03 idioms that are errors under C++11+ defaults in modern clang.
  • Guard -Wl,-no-undefined inside ifneq ($(platform), osx): Apple ld does not support this flag.

Tested on

  • macOS 14 (arm64), Apple clang 15 — platform=osxlibretro.dylib (494 KB)
  • Cross-compile for arm64-Linux (aarch64-linux-gnu-g++) — platform=unixlibretro.so (~500 KB)
  • Validated: SMB1 (HVC-SM) + HappyLee 4:57.31 fm2 (TASVideos #1715M) ran all 17,868 frames without crash via Python ctypes frontend.

Note on libretro-fceux/libretro.cp

The Makefile uses $(wildcard *.cpp) to collect source files, but the libretro shim is named libretro.cp (missing final p). A copy named libretro.cpp is needed alongside it. Not included in this patch as the right fix may be to update the Makefile glob to also match *.cp.

@bqw371 bqw371 closed this by deleting the head repository Jul 30, 2026
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

Successfully merging this pull request may close these issues.

1 participant