Please help me compiling code

I am new to c++ . I am from php background
I have 3 files main.cpp game.hpp and game.cpp(class file) all in same directory

//main.cpp code

1
2
3
4
5
6
7
8
#include "game.hpp"

int main()
{
   Game ngame;
   ngame.run();
   return 0;
}


after compiling the code i get error

undefined reference to Game::Game()
undefined reference to Game::run()
...

If is put content of game.cpp in main.cpp it works correctly, so there's nothing wrong with code i guess.

i am using makefile

please provide me command for compiling in terminal

Thank you
Hi @btrfly i use to
compile, (using GCC or Clang from command line)
GCC compiler
g++ main.cpp header_implementation.cpp -o exec_name

Clang
Clang++ main.cpp header_implementation.cpp -o exec_name


Thank you @eyenrique
its been 4 day since i am learning c++, my src of learning is Internet only.
I need suggestion on what build program shall i use cmake, boost build etc.
I need suggestion on what build program shall i use cmake, boost build etc.

None right now , those errors mean that the linker cannot find the given symbols.
You shouldn't need makefiles right now , just compile your source with
Compile :
$ g++ -o name_of_exec main.cpp game.cpp

Run:
$ ./name_of_exec

If you have just started , I suggest use an IDE , like Code::Blocks.
Last edited on
Thank you, i compiled the code successfully.
i could have used IDE but i wanted to learn how thing works at low level. i prefer not to use GUI.
i learned little cmake.

This might be off topic
My interests are in developing games. so i am learning c++ and sdl2 . using lazyfoo tutorial and other resources. I am using Ubuntu
Well, I would recommend SFML , I am totally biased here .
i think i'll stick with sdl . i am not sure

My interests are in developing games.
I like to use unity with c#. Though if you don't want a game engine but graphics for c++ I prefer SFML over SDL. When I tried SDL last (1 not 2) it seemed more c based than c++ which is why I preferred SFML.

I am newbie and I have no skill to judge them.

But i did little research and found

SFML is written in C++ so it is more C++ way ( plus point for me ).
its API is also good.
i have read it force you to use its style(impose, i don't prefer ).
I don't know if it supports multiple platform. i think it doesn't.

SDL is written in C, thus more C way(cant be helped)
never heard that it imposes.
it supports multiple platform(which is very good).

.
Last edited on
i have read it force you to use its style

Umm, no , Sounds like what some sdl fanboy would say.
Okay it does force you to use RAII so unfortunately you don't have to call init and clear functions.
If anything , I at-least consider SFML' s style as elegant and good. If over time you tend to prefer that and use it then I won't call it 'impose'.

I don't know if it supports multiple platform. i think it doesn't.

SDL does beat SFML to it , but SFML supports Mac,Linux and Windows and currently Android , iOS and Raspberry Pi support are under-development.(well, many things work but it's not much stable yet.)

Let's not turn this to SFML v SDL. Since I was the one to mention SFML , I'm sorry for unintended-ly throwing the troll-bait. Many forums are filled with these debates and I think the best way to find the one is find out yourself , try both
its good to know that support for Android is under development.

@a k n
If you wouldn't have have mentioned SFML, i would have been continued to be ignorant of it.
My main concern was coding style and support for Android which you cleared out.
Your posts helped me, i would not consider it troll bait.

Thank you guys
You are welcome @btrfly,
sorry for the late reply,

If you are using Ubuntu
you can use (on terminal)
vi editor + GCC or Clang compilers,
[download the latest version of vi]
Geany it's a good option but
are GUI.
btrfly: "i prefer not to use GUI"


regards!


Topic archived. No new replies allowed.