2012-01-24 44 views
0

试图使用Box2D的Iphone应用程序,但不知道如何将下面的C++头文件转换为Xcode目标C ...会有人请帮助我吗?先谢谢你!如何在Xcode中将C++转换为Objective C以编译Box2D?

#include <Box2D/Common/b2Settings.h> 
#include <cstdlib> 
#include <cstdio> 
#include <cstdarg> 

b2Version b2_version = {2, 2, 1}; 

// Memory allocators. Modify these to use your own allocator. 

void* b2Alloc(int32 size){ 
return malloc(size); 
} 

void b2Free(void* mem) 
{ 
    free(mem); 
} 

// You can modify this to use your logging facility. 

void b2Log(const char* string, ...) 

{ 
    va_list args; 
    va_start(args, string); 
    vprintf(string, args); 
    va_end(args); 
} 

回答

1

你尝试的Objective-C++模式?将您的.m/.cpp文件重命名为.mm

2

除了标题,所有代码都是C,而不是C++。例如,malloc/free是C例程。 C++中最近的例程将是new/delete

除非有其它的代码你不向我们展示了,你应该能够简单安全地指向C头文件,而不是:

#include <stdlib.h> /* was #include <cstdlib> */ 
#include <stdio.h> /* was #include <cstdio> */ 
#include <stdarg.h> /* was #include <cstdarg> */ 

...和代码块应该编译为C (因此在一个Objective-C项目中)。

相关问题