XCODE HELP - Main Method - objective-c

I am a newbie programming Objective C in Xcode. Can someone explain to me why the following prints nothing upon pressing build:
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
printf("Hello");
return NSApplicationMain(argc, (const char **) argv);
}

If you build the program, then run it, you will be able to read your "Hello" message in the Xcode Console (cmd-shift-r to open it, or check in the Run menu).
Otherwise, you will read a message explaining what went wrong.

Related

Programming with GLFW and Glew on Mac OS X

I have the following code:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import </usr/local/Cellar/glew/1.12.0/include/GL/glew.h>
#import </usr/local/Cellar/glfw2/2.7.9/include/GL/glfw.h>
int main(int argc, const char * argv[])
{
#autoreleasepool
{
if(!glfwInit())
{
exit(EXIT_FAILURE);
}
}
return 0;
}
I get the following errors when compiling: glew.h User-defined Issue Gltypes.h included before glew.h Modules Issue Declaration of PFNGLCOPYTEXSUBIMAGE3DPROC must be imported from module 'OpenGL.GL3' before it is required
There are another 19 errors that are all semantic errors. Does anyone know how to fix this?
As it turned out I didn't properly compile the library files.

Unable to instantiate the UIApplication subclass instance

i'm building a SpriteBuilder project and getting the error of:
" * Assertion failure in int UIApplicationMain(int, char **, NSString *, NSString *)(), /SourceCache/UIKit_Sim/UIKit-2903.23/UIApplication.m:2380
Unable to instantiate the UIApplication subclass instance. No class named NSApplication is loaded."
For the main.m code of:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
#autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, #"AppController");
return retVal;
}
}
What's the cause?
XCode is referring to the wrong info.plist file. In Build Settings, the info.plist path should be "Source/Resources/Info.plist" instead of "$(SRCROOT)/Source/libs/cocos2d-iphone/external/Chipmunk/xcode/main-Info.plist". Changing the path fixed it.

Calling Functions using Objective-C and C++

Alright, I'm trying to call a function in xcode but apparently it isn't working. I made an objective-c class, and typed in the following code into the implementation file:
#import "Person.h"
#implementation Person
void printthis()
{
NSLog(#"Hi, I have been printed");
}
int main(int argc, const char * argv[])
{
#autoreleasepool {
printthis();
}
return 0;
}
#end
Apparently, it returns the following error in xcode:
ld: 1 duplicate symbol for architecture x86_64
clang: error:
linker command failed with exit code 1 (use -v to see invocation)
Did you already have a main function somewhere else (probably main.m ?). If so the linker got confused -- you are not supposed to have duplicates of main function

error: ‘NSString’ undeclared (first use in this function)

I am getting this error when i try to compile Object-c program in cygwin Windows 7, but this program executed in Xcode.
main.m:5:3: error: ‘NSString’ undeclared (first use in this function)
#include <stdio.h>
int main (int argc, const char * argv[])
{
NSString *str1 = #"1st string";
NSString *str2 = #"2nd string";
NSLog(#"Hello, World!");
return 0;
}
Executed using the following CMD in cygwin,
gcc -c -Wno-import main.m
can you one help me how solve this compilation error.
Windows doesn't come with a Foundation library, so NSString isn't available by default. You should try GNUstep or you could cross-compile from Xcode on a Mac using Cocotron. Whichever you choose, look at its documentation to find out how to use it (at a minimum you'll need to #import <Foundation/Foundation.h> and link the Foundation library).
Make sure that you are have the following code at the top of your .h or .m file:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
You can also put the code in your Prefix.pch file.

How to import Objective-C classes into Console App

Step 1. Create a simple console app in Xcode
Step 2. Create simple objective C class in same project
Step 3. Try to import like this:
#include <stdio.h>
#import "MyClass.h"
int main (int argc, const char * argv[])
{
// insert code here...
printf("Hello, World!\n");
return 0;
}
Why won't this compile? Xcode error is "too many errors emitted stopping now"
Because your source file is a C module. Change the extension to .m. Better yet, start with the Foundation-based tool project template in Xcode.