Search code examples
objective-ccocos2d-iphone

Linker command failed when declaring int variable


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 {
...
}

Solution

  • Declare it static:

    static int test;
    

    Or const if its value should never change:

    const int test = 10;