如何在Xcode中将C++转换为Objective C来编译Box2D
How to Convert C++ to Objective C in Xcode to compile Box2D?
试图将Box2D用于Iphone应用程序,但不知道如何将以下C++头文件转换为Xcode Objective C…有人能帮我吗?提前感谢
#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);
}
除了头,所有的代码都是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项目中)。
您尝试过Objective-C++模式吗?将.m
/.cpp
文件重命名为.mm