在Xcode中编译一个C ++类:编译期间出错:stl向量 [英] compiling a C++ class in Xcode: error during compilation: stl vector

查看:194
本文介绍了在Xcode中编译一个C ++类:编译期间出错:stl向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++类,在linux上用gcc编译,在widows中编译。



boid.h:

  #ifndef BOID_CLASS_HEADER_DEFINES_H 
#define BOID_CLASS_HEADER_DEFINES_H
#includedefinitions.h

class Boid {

public:
//以随机位置,标题方向初始化boid和颜色
Boid(float SceneRadius,float NormalVel);

.....
protected:
...
};

#endif

并在boid.cpp中:

  #includeBoid.h

//用随机位置,方向和颜色初始化boid
Boid :: Boid(float SceneRadius,float NormalVel)
{
....
}

但是,当我在Xcode中编译此代码时,我收到以下错误:

  .h:错误:向量:没有这样的文件或目录

我想你可以采取C / C ++代码,并在Xcode中编译没有问题?



感谢



EDIT :添加了define.h

编辑2 :我在注释掉一对夫妇后得到一个不同的错误包括那里是空的:上面的向量错误。

  #ifndef BOID_NAV_DEFINES_H 
#define BOID_NAV_DEFINES_H
#include< stdlib.h>
#include< vector>
#includeVector3d.h
#includePoint3d.h
#includewin_layer.h
#endif


解决方案

是否在.m文件中包含C ++头文件?



.m文件被视为带有Objective-C扩展名的.c文件。



.mm文件作为具有Objective-C扩展的.cpp文件,则称为Objective-C ++



只要将任何.m文件重命名为.mm,右键单击或ctrl-单击并选择在Xcode中对文件重命名。


I have a C++ class that compiles fine on linux with gcc and on widows in visual studio.

boid.h:

#ifndef BOID_CLASS_HEADER_DEFINES_H
#define BOID_CLASS_HEADER_DEFINES_H
#include "defines.h"

class Boid {

public:
     // Initialize the boid with random position, heading direction and color
     Boid(float SceneRadius,float NormalVel);

     .....
protected:
     ...
};

#endif

and in boid.cpp:

#include "Boid.h"

// Initialize the boid with random position, heading direction and color
Boid::Boid(float SceneRadius,float NormalVel) 
{
    ....
}

However, I get the following error when I compile this code in Xcode:

Compiling Boid.h: "error: vector: No such file or directory"

Any ideas? I thought you could take C/C++ code and compile it in Xcode without issues?

Thanks

EDIT: Added defines.h (also added #endif to sample, but that was in the original code)

EDIT 2: I am getting a different error after a commenting out a couple of includes there were empty: the vector error above.

#ifndef BOID_NAV_DEFINES_H
#define BOID_NAV_DEFINES_H
#include <stdlib.h>
#include <vector>
#include "Vector3d.h"
#include "Point3d.h"
#include "win_layer.h"
#endif

解决方案

Are you including the C++ header in a .m file?

.m files are treated as .c files with Objective-C extensions.

.mm files are treated as .cpp files with Objective-C extensions, then it's called Objective-C++

Just rename any .m file to .mm, right-click or ctrl-click and select rename on the file in Xcode.

这篇关于在Xcode中编译一个C ++类:编译期间出错:stl向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆