JavaCake
JavaCake

Reputation: 4115

Undefined symbols, using C++ in iOS

I'm getting an error which I cannot resolve.

Undefined symbols for architecture i386:  
"ObjSurface::ObjSurface(std::string const&)", referenced from:
  -[RootViewController testObj] in RootViewController.o ld: 
       symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

ObjSurface.hpp

#include "Interfaces.hpp"

class ObjSurface : public ISurface {
public:
    ObjSurface(const string &name);
    int GetVertexCount() const;
    int GetLineIndexCount() const { return 0; }
    int GetTriangleIndexCount() const;
    void GenerateVertices(vector<float>& vertices, unsigned char flags) const;
    void GenerateLineIndices(vector<unsigned short>& indices) const {}
    void GenerateTriangleIndices(vector<unsigned short>& indices) const;
private:
    string m_name;
    vector<ivec3> m_faces;
    mutable size_t m_faceCount;
    mutable size_t m_vertexCount;
    static const int MaxLineSize = 128;
};

ObjSurface.cpp

ObjSurface::ObjSurface(const string &name) :
    m_name(name),
    m_faceCount(0),
    m_vertexCount(0)
{
    m_faces.resize(GetTriangleIndexCount() / 3);
    ifstream objFile(m_name.c_str());
    vector<ivec3>::iterator face = m_faces.begin();
    while (objFile) {
        char c = objFile.get();
        if (c == 'f') {
            assert(face != m_faces.end() && "parse error");
            objFile >> face->x >> face->y >> face->z;
            *face++ -= ivec3(1, 1, 1);
        }
        objFile.ignore(MaxLineSize, '\n');
    }
    assert(face == m_faces.end() && "parse error");
}

Useage in ViewController.mm:

#include "ObjSurface.hpp"
    surfaces[0] = new ObjSurface(path + "/Ninja.obj");

My build settings:

enter image description here

Do I have to define some kind of namespace in my iOS class (std)?

Upvotes: 0

Views: 655

Answers (1)

mattjgalloway
mattjgalloway

Reputation: 34912

Is ObjSurface.cpp actually being compiled and linked? i.e. it it in the "Compile sources" build phase? It sounds like it isn't.

Upvotes: 1

Related Questions