Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Last active November 25, 2023 21:13
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sindresorhus/d5c626fde1647f0b3e0d to your computer and use it in GitHub Desktop.
Save sindresorhus/d5c626fde1647f0b3e0d to your computer and use it in GitHub Desktop.
Compile Objective-C on the command-line with clang
# -fobjc-arc: enables ARC
# -fmodules: enables modules so you can import with `@import AppKit;`
# -mmacosx-version-min=10.6: support older OS X versions, this might increase the binary size
clang main.m -fobjc-arc -fmodules -mmacosx-version-min=10.6 -o main
@import Foundation;
int main() {
@autoreleasepool {
NSArray *args = [[NSProcessInfo processInfo] arguments];
if (args.count == 1) {
return 1;
}
NSString *input = args[1];
puts([input UTF8String]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment