Jump to content
  • Advertisement
Sign in to follow this  
Juliean

Game engine lib problems

This topic is 2035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...

Share this post


Link to post
Share on other sites
Advertisement

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...

Share this post


Link to post
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?

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!