Followers 0

# Game engine lib problems

## 11 posts in this topic

Hello,

so I've come to decide that its time to split up the code of my engine an the sample game I'm building with it. For now I've just had one solution, and one project, with game and engine code simply split up by different folders in Visual Studio. So I've tried to split it up in two different projects to begin with. I've tried to compile the engine as a static libary and link the game against it. This however doesn't seem to work very well, since I'm encountering a serious of errors when buildung the game:

1>c:\work\repo\editor\Rect.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\work\repo\editor\Rect.h(22): error C2143: syntax error : missing ',' before '&'
1>c:\work\repo\editor\Rect.h(24): error C2065: 'vPoint' : undeclared identifier
1>c:\work\repo\editor\Rect.h(24): error C2228: left of '.x' must have class/struct/union
1>          type is ''unknown-type''
1>c:\work\repo\editor\Rect.h(25): error C2065: 'vPoint' : undeclared identifier
1>c:\work\repo\editor\Rect.h(25): error C2228: left of '.y' must have class/struct/union
1>          type is ''unknown-type''
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\cmath(28): error C2039: 'acosf' : is not a member of 'global namespace''


This is e.g. Rect.h from my engines project:

#pragma once
#include <Windows.h>
#include "Vector.h"

struct Rect
{
public:
Rect(void)
{
x = 0, y = 0, width = 0, height = 0;
}
Rect(int x, int y, int width, int height)
{
this->x = x, this->y = y, this->width = width, this->height = height;
}

void Set(int x, int y, int width, int height)
{
this->x = x, this->y = y, this->width = width, this->height = height;
}

bool Inside(const Vector2& vPoint) const
{
int distanceX = vPoint.x - x;
int distanceY = vPoint.y - y;
return distanceX >= 0 && distanceX <= width && distanceY >= 0 && distanceY <= height;
}

Rect Merge(const Rect& rect) const
{
int x = max(this->x, rect.x);
int y = max(this->y, rect.y);
int x2 = min(this->x+this->width, rect.x+rect.width);
int y2 = min(this->y+this->height, rect.y+rect.height);
return Rect(x, y, x2-x, y2-y);
}

RECT GetWinRect(void) const
{
RECT r = {x, y, width, height};
return r;
}

int x, y, width, height;
};


With "Vector2", my personal integer vector class, obviously not being defined here. Although everything is working fine when compiling the engine to the lib (well, almost, I'll get to that later).

So do you know what could cause this error? Obviously, if you look at the last error message, not only my classes causes this but also something in the "cmath" header.

I've added "C:\Work\Repo\Editor" where all my .cpp and .h are to include directories for the Game, as well as linked against the .lib file currently located in "C:\Work\Repo\Release\". Anything else that I have to do in order to work with static libs?

Aside from that, I've also noticed that the .lib file generated is huge - 55 Mb, while the application previously built is only about 150 kb in size. Any possible reasons for that, or did I do something wrong? Maybe this is related to my errors...

0

##### Share on other sites

cmath puts the maths functions into namespace std so you want to qualify it as std::acosf if it is in a header (you could use using namespace std; in a cpp file).

Is the error in vector.h? Has it got the definition of Vector2 in it? Is there a semicolon at the end of the last class declaration in that file? Might be better posting vector.h anyway...

1

##### Share on other sites

Point is, I never made use of "acosf" or anything like those - there is actual dozens of errors messages regarding this libary. This is Vector.h:

#pragma once

class Vector2
{
public:
Vector2(void);
Vector2(int x, int y);
~Vector2(void);

double length(void) const;
Vector2& absolute(void);

Vector2 operator-(const Vector2 &v) const;
Vector2 operator/(int iDevisor) const;

Vector2& operator+=(const Vector2 &v);
Vector2& operator-=(const Vector2 &v);

Vector2& operator/=(int iDevisor);

int x,y;

};


And that is Vector.cpp:

#include "Vector.h"
#include <math.h>

#pragma region vector2

Vector2::Vector2(void) : x(0), y(0)
{
}

Vector2::Vector2(int x, int y) : x(x), y(y)
{
}

Vector2::~Vector2(void)
{
}

double Vector2::length(void) const
{
return sqrt((double)(x*x+y*y));
}

Vector2& Vector2::absolute(void)
{
x = abs(x);
y = abs(y);
return *this;
}

Vector2& Vector2::operator/=(int iDevisor)
{
x/=iDevisor;
y/=iDevisor;
return *this;
}

Vector2 Vector2::operator-(const Vector2 &v) const
{
return Vector2(x-v.x, y-v.y);
}

Vector2 Vector2::operator/(int iDevisor) const
{
return Vector2(x/iDevisor, y/iDevisor);
}

Vector2 & Vector2::operator-=(const Vector2 &v)
{
x -= v.x;
y -= v.y;
return *this;
}

Vector2 & Vector2::operator+=(const Vector2 &v)
{
x += v.x;
y += v.y;
return *this;
}

#pragma endregion


Both are included through "Math.h"

#pragma once
#include "Vector.h"
#include "Rect.h"

#define DEGTORAD(degree) ((D3DX_PI / 180.0f) * (degree))


Before splitting game and engine, everything compiled just fine, no error whatsoever. See anything suspicisous here?

0

##### Share on other sites

Yeah, that did the job, thanks! But now there is one last thing. Without further work, I get this error

fatal error C1083: Cannot open include file: 'd3dx9.h': No such file or directory


on every occasion where I included d3dx9.h in my engine. Obviously solvable by also adding the dx-include directory to my games include-dir list, but this shouldn't be necessary... should it? If no, what can I do to avoid that?

Also, I've still got the issue with the way to big .lib - in debug it is around 23 MB. Any advice on that, too?

0

##### Share on other sites

Is it in angle brackets? Otherwise you may have to add the sdk path to your additional include directories.

Don't worry about the lib size, when it is linked into your exe it strips out anything not required.

1

##### Share on other sites

Yes, indeed it is:

#pragma once
#include <d3dx9.h>
#include <d3d9.h>


Oddly enough, it only has problems finding the d3dx9.h - d3d9 doesn't throw an error, even if I swap their position, and although both are located in the same folder. Some idea or do I really have to add the path to the games additional include directories? Wouldn't that be really weird, say for example if I was using more than just the directx lib to always have to add all needed directories to every game I wanted to use the engine?

0

##### Share on other sites

Are you sure it is looking in the folder you think it is? Have you got more than 1 direct X SDK install? Try searching your hard drive for all occurences of d3d9.h and see if they all have a d3dx9.h in there too. That's all I can think of...

1

##### Share on other sites

Well, I didn't install more than one DirectX SDK, but since I'm on windows 8 (on that PC), there is one Folder "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin" which has only a d3d9.h but no d3d9x.h and, as well as one "C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86" folder, same with only the d3d9.h. Could this be the reason? I added "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include", the path to my DirectX sdk, to the additional include paths of my engine...

Edited by The King2
0

##### Share on other sites

Yes, that will be the problem. Looks like the Windows SDK path is being used instead of the DirectX SDK path. What definitions do you need d3dx9.h for anyway?

2

##### Share on other sites

What definitions do you need d3dx9.h for anyway?

I'm using the D3DXSprite, D3DXMATRIX, etc... , if thats what you are asking for? Appearantly, I'd additionally need to tell the linker to link to the d3d9.lib, as well as the d3dx9 and some other libs. Gosh, I hate Windows 8 :/

Well now granted I did, since its OK for now (going to test if this persists on Windows 7 tomorrow) c+p all the include and link stuff from my engine project. I still get some unresolved symbol errors. Well, at least we are partially in the territory of the game project now:

1>LightAttributeCtrl.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall GuiObject::OnKeyStroke(char)" (?OnKeyStroke@GuiObject@@UAEXD@Z)
1>MaterialAttributeCtrl.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall GuiObject::OnKeyStroke(char)" (?OnKeyStroke@GuiObject@@UAEXD@Z)
1>ObjectAttributeCtrl.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall GuiObject::OnKeyStroke(char)" (?OnKeyStroke@GuiObject@@UAEXD@Z)

Whereas the function is declared as :

class GuiObject {
...
virtual void OnKeyStroke(TCHAR key);
...
}


and defined as

void GuiObject::OnKeyStroke(TCHAR key)
{
}
`

I won't post the whole GuiObject.h code since it is really huge and probably contains nothing to help solve the problem. <Windows.h> is included in the header, however, so is GuiObject.h to each of the Controller-classes throwing the error. Some ideas why it could be crashing on this very function? Ouch, silly me, forgot to set the new project to unicode. Hrmpf. Could slap myself for this. Anyway, for now it is working, except this one very annoying need-to-include-stuff-thats-already-included-in-my-engine - thing. Out of interest, how does other engines handle this? Did the windows 8 SKD completely drop the d3dx9-stuff or is there any other way to correctly include it?

Edited by The King2
0

##### Share on other sites

Out of interest, how does other engines handle this?

i was going to say, you seem to be doing it the hard way.

don't make the game library a separate project. just make it an existing .cpp and .h file you add to your game project.

IE just another module.

only difference, this module has generic reusable code and is include in many different game projects, instead of being game specific and used in just one project..

always set your compiler options first when you start a new project. I keep a 3 page list of all the correct settings for a release build of any game. this avoids stuff like wrong char type. that one bites me a lot too, hence the lists, way too much to memorize.

0

## Create an account

Register a new account