-3

I'm making a math engine using c++ and I created 3 classes (vector, matrix and quaternion).When I compile my code using g++ I have an error and I don't know how to fixit, if someone can help me it would be appreciated.

Here is my vector.hpp code:

#include "matrix.hpp"
#include "quaternion.hpp"

#include <iostream>
#include <cmath>

namespace helix{
    class vector{
    public:
        float x;
        float y;
        float z;

        ...
        
        vector();
        vector(float x, float y, float z);
        vector(const vector& vec);

        ...
    }
}

Here is my terminal output:

Undefined symbols for architecture x86_64:
  "helix::vector::vector(float, float, float)", referenced from:
      _main in main-efde0e.o
  "helix::vector::~vector()", referenced from:
      _main in main-efde0e.o

If you need more informations, ask me !]

[ You can access source code on my GitHub: https://github.com/miishuriinu/game_engine ]

miishuriinu
  • 117
  • 1
  • 9

1 Answers1

3

Your Makefile only compiles main.cpp: it only uses the compiler as follows

g++ -std=c++17 src/main.cpp -o bin/pgm -I include -L lib -l glfw.3.3 -l GLEW.2.2.0 -framework OpenGL

You need to compile and link the other cpp files in src/maths as well, since the methods are defined there.

chi
  • 111,837
  • 3
  • 133
  • 218
  • How can I do that ? @chi – miishuriinu Apr 12 '21 at 11:52
  • 1
    @miishuriinu You should find some "compile & link" Makefile tutorial, there should be many. Anyways, to do that without a Makefile one runs `g++ -c file1.cpp`, `g++ -c file2.cpp`, ... to compile (this will produce a bunch of .o files), and then links everything as `g++ -o executable_name file1.o file2.o ...`. A Makefile usually reproduces these steps with the correct dependencies so to avoid recompiling what did not change. – chi Apr 12 '21 at 11:59