Undefined reference to `_exit' and friends

I'm not a compiler guy, so I don't know the correct resolution to this issue, but at least I can describe it. While working in C, I ran across a set of curious errors once I made a call to sprintf():

[...]/stdlib/abort.c:59: undefined reference to `_exit'
[...]/reent/signalr.c:53: undefined reference to `_kill'
[...]/reent/signalr.c:83: undefined reference to `_getpid'
[...]/reent/writer.c:49: undefined reference to `_write'
[...]/reent/closer.c:47: undefined reference to `_close'
[...]/reent/fstatr.c:55: undefined reference to `_fstat'
[...]/reent/isattyr.c:52: undefined reference to `_isatty'
[...]/reent/lseekr.c:49: undefined reference to `_lseek'
[...]/reent/readr.c:49: undefined reference to `_read'

Removing the calls to sprintf() got these errors to go away.

Stack Overflow suggests this thread, which pretty accurately describes my situation. The suggested solution is to compile with --specs=nosys.specs for reasons that kind of went over my head. I added the switch into C_API/buildsupport/common.mk in the recipe for pdex.elf (line 145 in the 1.12.0 SDK) and I was able to compile with no issue.

There may be other standard C functions that cause this to pop up. If all else fails, the above solution does appear to get around the issue without introducing any new ones.

The problem is newlib's sprintf() links to some odd system functions you wouldn't expect and which aren't available in the scope of the game. I don't recall off the top of my head what limitations --specs=nosys.specs has, but if the linker doesn't have any complaints it seems like it should be fine. I've got setup.c shims working for printf(), snprintf(), and asprintf(), like we have for malloc etc., will get those into a future update. I didn't include sprintf() since it's always better to use snprintf().. but I'll think about adding that too.

Please provide more information on how to fix this. Where exactly I have to put --specs=nosys.specs or what does I added the switch into C_API/buildsupport/common.mk in the recipe for pdex.elf (line 145 in the 1.12.0 SDK) ? What is switch? Switch operator? how once can add switch operator to a line like $(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@? I tried to add to cmake command but no luck. Thanks

In file C_API/buildsupport/common.mk, there is a recipe for a file called /pdx.elf:

$(OBJDIR)/pdex.elf: $(OBJS) $(LDSCRIPT)
	$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@

--specs=nosys.specs goes somewhere in the recipe, such as this:

$(OBJDIR)/pdex.elf: $(OBJS) $(LDSCRIPT)
	$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@ --specs=nosys.specs

Linking this post detailing some additional steps for Visual Studio.