3
votes

I have successfully added Lua to a default Xcode template project by following the process described by this very helpful post, and got the "Hello, world." text printing.

However, when I try to add Lua to my existing Cocos2D/Box2d project, following exactly the same process, I get a compile error:

Undefined symbols for architecture i386:

"luaL_newstate()", referenced from ...

My search results on this error refer to one of these possible problems, which I think are OK in my case:

  • The target's Build Phases -> Compile Sources - but the same Lua.c files are in both the default template project and my Cocos2D/Box2d project
  • I set the header search paths of the default project to match those in the Cocos2D/Box2d project, and the template still compiles fine.
  • All the frameworks used by the template project are also in my Cocos2D/Box2d project.

What am I missing?

Any help would be much appreciated. Thanks!

1

1 Answers

3
votes

I've done this integration recently, and the problem that you have there is that the Lua files are written in C, and Box2D is C++.

You will need to wrap the Lua includes like that:

#ifdef __cplusplus
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#endif

That should fix the issues, if not post a comment with the error you are getting.