Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling a C++ class in Xcode: error during compilation: stl vector

Tags:

c++

xcode

porting

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
like image 825
cbrulak Avatar asked Feb 10 '09 23:02

cbrulak


3 Answers

I hope this will help. After updating xCode to version 10, I have had issues including < map > and < vector > libraries. Found an easy solution by changing the C++ library type in the project's build settings (target's Build Settings):

C++ Standard Library: libc++ (LLVM C++ standard library with C++ 11 support)

Compiled without any problem.

like image 132
DrArt Avatar answered Nov 20 '22 13:11

DrArt


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.

like image 24
epatel Avatar answered Nov 20 '22 13:11

epatel


Without changing any .m to .mm or anything like that, if you click your project, click tagets->build settings go all the way down to "LLVM GCC 4.2 - Languages" (new xcode says "Apple LLVM compiler 4.2") you will see Compile Sources As change that value to Objective-C++;

like image 17
John Riselvato Avatar answered Nov 20 '22 12:11

John Riselvato