简体   繁体   中英

Problems with headers and linker errors (new to C++)

I'm new to c++ and I'm having some trouble with making a header file. The exact error I'm getting is

obj.obj : error LNK2019: unresolved external symbol "float * __cdecl getVertices(class std::basic_string,class std::allocator >,int,float *)" (?getVertices@@YAPAMV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HPAM@Z) referenced in function "struct ObjModel __cdecl importObj(void)" (?importObj@@YA?AUObjModel@@XZ)

The bugs/solutions I'm seeing seem much more complicated that what I'm doing. Here's my header, which I suspect is wrong.

//obj.h
#ifndef OBJ_H_INCLUDED
#define OBJ_H_INCLUDED

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <iostream>
using namespace std;

struct ObjVertex {
     float x, y, z;
};

struct ObjTriangle {
     int Vertex[3];
     int Normal[3];
};


struct ObjModel {
     int NumVertex, NumNormal, NumTexCoord, NumTriangle;
     ObjVertex *VertexArray;
     ObjVertex *NormalArray;
     ObjTriangle *TriangleArray;
};

//function prototypes
float* getVertices(string buf, int i, float* ret);
ObjModel importObj();
char* subString(char* buf, int b, int e);

#endif

I've just started in C++ but I have experience in Java and C, so it's probably an issue with me not knowing some C++ specific thing.

There is no implementation for float* getVertices(string buf, int i, float* ret); hence you get a linker error.

您必须在声明了getVertices模块上附加模块。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM