'cmath' file not found

本文详细介绍了如何在C++项目中解决Box2D库中的b2Vec2类型与Cocos2D库中数学类型的重复利用问题,通过将main.m改为main.mm文件,成功解决了cmath、iostream等相关预编译指令无法正常引入的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

box2d 的 b2Vec2 类型和 cocos2d 的 CGPoint,CGSize, CGRect,我想拿出来自己用,

于是新建了一个 Terminal 工程。

因为 CGPoint 和 苹果自带的 CoreGraphics里面自带的~

而 box2d 里面的 b2Vec2 类型我也经常用到,

包含 b2Vec2 类型定义的头文件 b2Math.h 里面同时也包含了不少 有用的,线程的方法,

因此我很想来重复利用这些现成的东西。

但是遇到了一些问题:

‘cmatch’ file no found, 'iostream' not recognized等等,

包含在 b2Math.h 的

#include <cmath>

#include <cfloat>

#include <cstddef>

#include <cassert>

#include <limits>

等预编译指令,竟然每一个都有问题,都无法正常的引入!

后来找到了一篇帖子:

C++ #include help?

Quote:
Originally Posted by BlackBlade View Post
cmath related errors are simply this, "cmath" file not found, and iostream is not recognized, i then went through the whole list of include functions(not sure what to call them) and the closest thing on there is IOsurface or IOsurface.h
Did you create a C++ project and not Objective-C or Cocoa? I you pick a Cocoa application you will get this error.



Quote:
Originally Posted by subsonix View Post
Did you create a C++ project and not Objective-C or Cocoa? I you pick a Cocoa application you will get this error.
i am an idiot, i figured it out, i never made a file in the project i simply used main.m
just tried making a c++ file and it worked

thanks a lot, now i won't fail! thanks again


根据帖子里面所提到的相关信息,在我将 main.m 改成 main.mm 文件以后,编译成功通过~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值