如何转换 C++ Xcode 中的 Objective C 来编译 Box2D?

发布于 2024-12-28 16:35:52 字数 622 浏览 1 评论 0原文

尝试将 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);
}

Trying to use Box2D for an Iphone App but do not know how to convert the following C++ header file to Xcode Objective C... Would someone please help me? Thank You in Advance!

#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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猛虎独行 2025-01-04 16:35:52

除了标头之外,所有代码都是 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 项目中)。

Except for the headers, all of that code is C, not C++. For example, malloc/free are C routines. The nearest routines in C++ would be new/delete.

Unless there is other code you're not showing us, you should be able to simply and safely point to C headers, instead:

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

...and that chunk of code should compile as C (and therefore within an Objective-C project).

暮年 2025-01-04 16:35:52

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

Did you try Objective-C++ mode? Rename your .m/.cpp files to .mm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文