views:

3747

answers:

7

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
+1  A: 

Not sure if you forgot to paste, but you have an unterminated #ifndef

What's inside defines.h ?

Edit: You seem to have found the solution. One more remark:

#include <stdlib.h>

For C++, please:

#include <cstdlib>

:D

turbovince
added defines.h to the question, also, #endif is in the original code
cbrulak
A: 

Definitely, something in defines.h is affecting the class definition.

Diego Sevilla
+2  A: 

Make sure you're compiling it as C++. Right click the file in XCode and select Get Info and make sure that File Type is set to sourcecode.cpp.cpp for the implementation files.

codelogic
+1  A: 

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.

epatel
A: 

Your example output suggests 68 errors but you have only posted a couple. Are the others known to be irrelevant?

dominic hamon
A: 

Assuming you're talking about the OS X XCode, that uses gcc to do the actual compiling. So there should be no difference between that and Linux, other than maybe different versions of gcc.

First thing that jumps out at me here is that you've typed "boid.h" as the name of the file, but you're including "Boid.h". Assuming that's not a typo, I would expect that to cause trouble on both Linux and OS X....

Edited to answer the new question: Hmmm... vector is definitely part of Xcode: /Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/vector on my machine.

Further thought: If you port the source and makefiles from the Linux build over to the Mac, you can probably just compile it from the command line exactly like you do on Linux....

Sol
A: 

This issue had two errors:

  • one of my includes had a typo which caused a compile error
  • the vector not found error was fixed by the .m files to .mm
cbrulak