报名参加这个问题。为什么我这样的代码会出错呢?
FuzzyObject.h:
#ifndef FUZZYOBJECT_H
#define FUZZYOBJECT_H
#include <iostream>
#include <d3d9.h>
#include <d3dx9.h>
class FuzzyObject {
public:
FuzzyObject();
typedef struct tagFMaterial* FMaterial;
typedef struct tagFMesh* FMesh;
typedef struct tagFuzzyForm {
D3DXVECTOR3 pos;
D3DXVECTOR3 rot;
D3DXVECTOR3 scale;
D3DXVECTOR3 forward;
D3DXVECTOR3 up;
} FuzzyForm;
typedef struct tagObject* Object;
typedef enum ObjectType {
FO_STATIC = 0,
FO_ANIM = 1,
FO_OBJ = 2,
FO_CAMERA = 3,
FO_LIGHT = 4
} Type;
typedef enum ObjectCollider {
BOX = 0,
SPHERE = 1,
MESH = 2
} Collider;
static FuzzyObject::Object InitializeObj(std::string ObjName, FuzzyObject::ObjectType type, bool render, FuzzyObject::FuzzyForm xform);
D3DXMATRIX UpdateTransform(FuzzyObject::FuzzyForm xform, FuzzyObject::Object camera);
void UpdateObject(Object);
~FuzzyObject();
};
#endif
FuzzyObject.cpp:
#include <d3d9.h>
#include <d3dx9.h>
#include <iostream>
#include <FuzzyObject.h>
#include <Personality.h>
#include <GFX.h>
#include <d3d9.h>
#include <d3dx9.h>
struct tagFMesh{
LPD3DXMESH mesh;
LPD3DXBUFFER adjBuf;
LPD3DXBUFFER materialBuf;
};
struct tagFMaterial {
LPD3DXEFFECT Shader;
LPDIRECT3DTEXTURE9 texture0, texture1, texture2;
LPDIRECT3DTEXTURE9 bump0, bump1, bump2;
D3DXVECTOR4 Color;
D3DXMATRIX MVP;
};
struct tagObject {
std::string name;
FuzzyObject::Type type;
bool Physics;
FuzzyObject::Collider collider;
bool renderable;
FuzzyObject::FuzzyForm transform;
D3DXMATRIX FFMATRIX;
Personality::Behaviour CustomCode;
FuzzyObject::FMaterial materialDef;
FuzzyObject::FMesh mesh;
};
D3DXMATRIX FuzzyObject::UpdateTransform (FuzzyObject::FuzzyForm xform, FuzzyObject::Object camera) {
D3DXMATRIX pos, rot, scale;
D3DXMATRIX M, V, P;
D3DXMATRIX MVP;
D3DXMatrixTranslation(&pos, 0.0f, 0.0f, 0.0f);
D3DXMatrixRotationYawPitchRoll(&rot, D3DXToRadian(xform.rot.x), D3DXToRadian(xform.rot.y), D3DXToRadian(xform.rot.z));
D3DXMatrixScaling(&scale, xform.scale.x, xform.scale.y, xform.scale.z);
D3DXMatrixMultiply(&M, &scale, &rot);
D3DXMatrixMultiply(&M, &rot, &pos);
D3DXVECTOR3 from = D3DXVECTOR3(camera->transform.pos.x, camera->transform.pos.y, camera->transform.pos.z);
D3DXVECTOR3 to = D3DXVECTOR3(cos(camera->transform.rot.x*180/D3DX_PI), tan(camera->transform.rot.y*180/D3DX_PI), sin(camera->transform.rot.z*180/D3DX_PI));
D3DXVECTOR3 up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH( &V, &from, &to, &up );
D3DXMatrixPerspectiveFovLH( &P, D3DXToRadian(60.0f), 640/480, 0.01, 1000);
MVP = M * V * P;
return MVP;
}
FuzzyObject::Object FuzzyObject::InitializeObj (std::string ObjName, FuzzyObject::ObjectType type, bool render, FuzzyObject::FuzzyForm xform ) {
FuzzyObject::Object obj;
obj->transform = xform;
obj->name = ObjName;
obj->type = type;
obj->renderable = render;
return obj;
}
void FuzzyObject::UpdateObject(FuzzyObject::Object obj) {
obj->FFMATRIX = UpdateTransform(obj->transform, NULL);
}
发生的是,我在链接器中收到此错误:
Error: Undefined reference to 'FuzzyObject::InitializeObj()'
来自FuzzyGame.cpp的,其中调用完成如下:
FuzzyObject::Object obj = FuzzyObject::InitializeObj(/*my parameters g here*/);
有什么想法吗?我不知道为什么要这样做...... :(
答案 0 :(得分:0)
调用function()
的翻译单元需要与header.o
相关联。很可能这在构建系统中没有指定。请制作一个MCVE,这会鼓励人们帮助你。
您必须将Dev-C++
项目配置为确认FuzzyObject.h
和FuzzyObject.cpp
作为FuzzyGame.cpp
的依赖项。这样,生成的Makefile将包含正确的链接指令,以解析对FuzzyObject::InitializeObj()
的引用。
半条命4祝你好运,我们都期待着它:)。
答案 1 :(得分:0)
这是我的makefile人。 :)
# Project: FLDR-D3D9
# Makefile created by Dev-C++ 5.7.1
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
RES = FLDR-D3D9_private.res
OBJ = GFX.o FuzzyObject.o Personality.o Main.o FuzzyGame.o $(RES)
LINKOBJ = GFX.o FuzzyObject.o Personality.o Main.o FuzzyGame.o $(RES)
LIBS = -L"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib32" -L"C:/Program Files (x86)/Dev- Cpp/MinGW64/x86_64-w64-mingw32/lib32" -static-libgcc -mwindows ../../../../Dev-Cpp/lib/libd3d9.a ../../../../Dev-Cpp/lib/libd3dx9.a ../../../../Dev-Cpp/lib/libpthreadGC2.a -m32
INCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include" -I"C:/Users/112mackailj/Documents/DirectX 9 Projects"
CXXINCS = -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64- mingw32/4.8.1/include" -I"C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++" -I"C:/Users/112mackailj/Documents/DirectX 9 Projects"
BIN = FLDR-D3D9.exe
CXXFLAGS = $(CXXINCS) -m32
CFLAGS = $(INCS) -m32
RM = rm.exe -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
GFX.o: GFX.cpp
$(CPP) -c GFX.cpp -o GFX.o $(CXXFLAGS)
FuzzyObject.o: FuzzyObject.cpp
$(CPP) -c FuzzyObject.cpp -o FuzzyObject.o $(CXXFLAGS)
Personality.o: Personality.cpp
$(CPP) -c Personality.cpp -o Personality.o $(CXXFLAGS)
Main.o: Main.cpp
$(CPP) -c Main.cpp -o Main.o $(CXXFLAGS)
FuzzyGame.o: FuzzyGame.cpp
$(CPP) -c FuzzyGame.cpp -o FuzzyGame.o $(CXXFLAGS)
FLDR-D3D9_private.res: FLDR-D3D9_private.rc
$(WINDRES) -i FLDR-D3D9_private.rc -F pe-i386 --input-format=rc -o FLDR-D3D9_private.res -O coff