I hate answering my question, but here is a solution that I found deep in the g++ man page, I tested it and it works on what I want ...
g++ has the -D flag, which allows you to define macros when compiling object files. I know what you think of poppies, but listen to me ... You can use macro definition to effectively rename a character. In my case, I can run the following command to create an object file for my student code without their main file: g++ -D main=__students_main__ main.cpp -c -o main.nomain.o .
Creates an object file with its int main , defined as int __students_main__ . Now this may not necessarily be called directly, since they could define main as int main(void) or with various combinations of argc and argv , but this allows me to efficiently compile their function.
The final compiler is as follows:
g++ -c -D main=__students_main__ main.cpp -o main.nomain.o g++ -c mymain.cpp -o mymain.o g++ main.nomain.o mymain.o -o mymainstudentsfoo.out
For my purposes, I wanted to create a Makefile that would execute this automatically (ish), and I believe this is relevant to this discussion, so I will post what I came up with:
HDIR=./
source share