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
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 ===
both functions are called from Scene.cpp:
#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
So... now I'll give the code tha (doubly) shows that the parameters are as they should be
Triangle.h
#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
and Triangle.cpp
#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
It is most likely a linking issue.
What library or object file is Triangle class in?
Is it in the Library list?
Tim S
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.
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
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:
-------------- 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
Some of the parts of minGW GCC does not like spaces in file names. This might be the cause.
What object file contains triangle code?
DrawEngine.o
ErrorHandler.o
FileHandler.o
Game.o
Scene.o
Vertex.o
main.o
Core.o
The order of object files could be wrong, but I have never had it happen in Code::Blocks. I am guessing the object file with the Triangle class is not in the list above.
Please re-compile the Triangle class and post the Build Log.
Tim S
That gave me the error that the file was not assigned to any build (knowing the problem now it was easy to fix it).
Thanks a lot for helping me fix this.
Jasper