I have the following file:
doSomething.m
with the following implementation:
#import <Foundation/Foundation.h>
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
@autoreleasepool {
NSLog(@"main");
}
return 0;
}
if I want to compile I need to run the following command:
clang -framework Foundation doSomething.m -o doSomething-exec
and to see any output and I need to execute the following command:
./doSomething-exec
My question to you guys there is a way just to build/execute the code in the doSomething.m
?
I don't want to be compiling and generating the output file and then executing the executable.
Sure. Write a build script. It's very common for projects of any size to include a make file or some other sort of script that takes care of all the steps needed to build the project, often with a variety of parameters for building for different targets or with different options. Scripts are a great way to simplify repetitive operations, and it's exactly the right way to handle the repetitive task that you're facing. If you've got lots of these single-file projects, you could have the script take the name of the source file as a parameter.
Your script doesn't have to be anything fancy: just list the commands that you'd normally issue in a text file prefixed with
#!/bin/sh
(or whatever your favorite shell is), like:Then make your script executable, and you're ready to go.
Another option is to create an Xcode project with a target for your
doSomething
product. That's a pretty typical modus operandi for developers working in the usual iterative edit-compile-run fashion.