User forums > Using Code::Blocks

errors I can't make sense of

(1/2) > >>

Jasper:
I have two errors in my project which I can not make any sense of, and M$VS does not give any problems when compiling the project. As my problem only involves a few of the most simple classes, I will post some of the code here.

The build messages

--- Code: ---Debug Win32\Scene.o:: In function `ZN5Scene10initializeEv':C:/Documents and Settings/Jasper/My Documents/Visual Studio 2005/Projects/GameEngine/GameEngine/Scene.cpp:26: undefined reference to `Triangle::Triangle(Vertex, Vertex, Vertex, float)'
Debug Win32\Scene.o:: In function `ZN5Scene6updateEf':C:/Documents and Settings/Jasper/My Documents/Visual Studio 2005/Projects/GameEngine/GameEngine/Scene.cpp:46: undefined reference to `Triangle::update(float
:: === Build finished: 0 errors, 0 warnings ===

--- End code ---

both functions are called from Scene.cpp:

--- Code: ---
#include "Scene.h"

#include "Triangle.h" // included this trying (but failing) to fix the problem
// Triangle.h, Vertex.h and DrawEngine.h are all actually included in the header

Scene::Scene(DrawEngine *arg_drawEngine, ErrorHandler *arg_errorHandler)
{
    drawEngine = arg_drawEngine;
    errorHandler = arg_errorHandler;

    triangle = NULL;
} // Scene


Scene::~Scene()
{
    clearAll();
} // ~Scene

bool Scene::initialize()
{
    Vertex v1(0.866f, -0.5f, 0.0f);
    Vertex v2(0.0f, 1.0f, 0.0f);
    Vertex v3(-0.866f, -0.5f, 0.0f);

    /* ---------------------- the following line gives our first error ------------------------ */
    triangle = new Triangle(v1, v2, v3, 0.0f);

    if (!triangle)
    {
        return false;
    }

    return true;

} // initialize

bool Scene::clearAll()
{
    SAFE_DELETE(triangle);

    return true;
} // clearAll

bool Scene::update(float deltaTime)
{

    /*----------------- and this line gives the next error------------------- */
    triangle->update(deltaTime * 30.0f);

    drawEngine->render(triangle);

    return true;
} // update

--- End code ---

So... now I'll give the code tha (doubly) shows that the parameters are as they should be

Triangle.h

--- Code: ---#ifndef Triangle_h
#define Triangle_h

#include "Vertex.h"

class Triangle
{
public:
    Triangle(Vertex vertex1, Vertex vertex2, Vertex vertex3, float arg_angle);
    virtual ~Triangle();

    void update(float arg_angle);

    Vertex v1;
    Vertex v2;
    Vertex v3;

    float angle;
};


#endif // Triangle_h

--- End code ---

and Triangle.cpp

--- Code: ---
#include "Triangle.h"

Triangle::Triangle(Vertex vertex1, Vertex vertex2, Vertex vertex3, float arg_angle)
{
    v1 = vertex1;
    v2 = vertex2;
    v3 = vertex3;

    angle = arg_angle;
} // Triangle

Triangle::~Triangle()
{

} // ~Triangle

void Triangle::update(float arg_angle)
{
    angle += arg_angle;
} // update

--- End code ---

stahta01:
It is most likely a linking issue.
What library or object file is Triangle class in?
Is it in the Library list?

Tim S

Jasper:
actually, the triangle class is made in my project (as provided, Triangle.h and Triangle.cpp). I may have misunderstood your question, but these files have the contents that I posted and they are in the project management between the other files.

stahta01:
Turn on Full Compiler Logging, I think this works for MSVC.

Settings -> "compiler and debugger"
Tab "Other Settings" the rightmost tab
Set "Compiler Logging" to "Full command Line"

Rebuild project
Post the "Build Log"

Tim S

Jasper:
To be more clear, I use GCC (MinGW) in codeblocks and I tried the same project in the MSVC IDE and there it worked. I will try what you said now.

edit, here's the log:


--- Code: ----------------- Build: Debug Win32 in GameEngine ---------------
mingw32-g++.exe -LC:\MinGW\lib  -o GameEngine.exe "Debug Win32\DrawEngine.o" "Debug Win32\ErrorHandler.o" "Debug Win32\FileHandler.o" "Debug Win32\Game.o" "Debug Win32\Scene.o" "Debug Win32\Vertex.o" "Debug Win32\main.o" "Debug Win32\Core.o"    -lglfw -lopengl32 -luser32 -lglu32  -mwindows
Debug Win32\Scene.o: In function `ZN5Scene10initializeEv':C:/Documents and Settings/Jasper/My Documents/Visual Studio 2005/Projects/GameEngine/GameEngine/Scene.cpp:26: undefined reference to `Triangle::Triangle(Vertex, Vertex, Vertex, float)'
Debug Win32\Scene.o: In function `ZN5Scene6updateEf':C:/Documents and Settings/Jasper/My Documents/Visual Studio 2005/Projects/GameEngine/GameEngine/Scene.cpp:46: undefined reference to `Triangle::update(float)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version