0

When i declare a global variable, I get the error:

linker command failed with exit code 1 (use -v to see invocation)

Here is the code:

import "menuplay.h"

import "buttonmanager.h"

int  test; //<--------------when i  declare  it show  error Apple Mach-O Linker Error

@interface lessonone : CCLayer {
...
}
1
  • Do not use global variables in objective C : - Commented Mar 16, 2013 at 16:27

1 Answer 1

1

Declare it static:

static int test;

Or const if its value should never change:

const int test = 10;
Sign up to request clarification or add additional context in comments.

3 Comments

static int test; Can change value in other method ? This it no error but i define value in menu.mm test=10 when i show test in menuplay.mm value =0,why not =10?
because it's a different variable. In menuplay.mm you will have to declare it as: extern int test;
stackoverflow.com/questions/8808159/… All you need is to use plain old C global variables. First, define a variable in your main.m, before your main function: #import <...> // Your global variable definition. type variable; int main() { ... Second, you need to let other source files know about it. You need to declare it in some .h file and import that file in all .m files you need your variable in: // .h file // Declaration of your variable. extern type variable;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.