问题
I'm working up a game in XCode, and I want to add a helper application that uses the main application's various classes to build the main application's data files.
Specifically: The main application is a card game. I want a helper app that uses the classes such as card.m while it creates the deck.xml files for the deck of custom cards the game uses.
My intuition is that the natural way to do this is to add a second compile target to the application, "Card Adder", to build this xml file. Unlike the main app, which is Cocoa Touch, I can make this one as a Shell application, to further make it quick & dirty.
Here's my hang up, and my question: What kicks off as the main routine for this second target? Looking over my existing main.m file, I see it's only associated with the main game app. So far so good. But of course I can't add a second main.m file for the helper/shell app.
How do I get around this? What do I use in place of a main.m? How do I signal to the compile target "Card Adder" that this new file will contain it's main subroutine?
回答1:
It's not the name of the file, but the name/signature of the function
int main(int argc, char *argv[])
That matters. Just make a file with this function in it. You can have only one main per application.
回答2:
You may actually be able to have two main.m files. Put them in different folders on the file system. Add one to one target, and another to the other target.
来源:https://stackoverflow.com/questions/3321334/xcode-two-targets-two-main-files