KnightOS/KnightOS

z80e-sdl macOS linker error: undefined symbol _main

nmosier opened this issue · 5 comments

The sequence of commands I performed to get the error on macOS 10.14.2 (Mojave):
$ cmake -Denable-sdl=YES .
$ make
...
[100%] Linking C executable bin/z80e-sdl
ld: warning: text-based stub file /System/Library/Frameworks//Cocoa.framework/Cocoa.tbd and library file /System/Library/Frameworks//Cocoa.framework/Cocoa are out of sync. Falling back to library file for linking.
...
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [frontends/sdl/bin/z80e-sdl] Error 1
make[1]: *** [frontends/sdl/CMakeFiles/z80e-sdl.dir/all] Error 2
make: *** [all] Error 2

It seems like SDL might be redefining main as SDL_main with the intention of implementing main() itself, but then why is main undefined?

https://stackoverflow.com/questions/11976084/why-sdl-defines-main-macro

That shouldn't be the issue, or it wouldn't build properly on Linux.

Mind uploading a preprocessed copy of frontends/sdl/main.c produced on the system with the error? That might make it easier to solve.

Wait nope, I take that back. On my Linux system, the SDL build links against a static library file libSDLmain.a. I suspect we're missing a dependency on OS X, which is why the real main is present on Linux but not OS X.

Been about a year since activity, and we've since had reports of compilation succeeding without issue. Closing this now.