Sign in to follow this  
c4c0d3m0n

Compiling my own game engine [C++] [no main()]

Recommended Posts

Hi all I'm writing my own little Game Engine. It is basically just a good collection of classes that will do things like state management, resource management, some graphics functions, etc. I like to compile my code once in a while, just to see if I'm doing things that are not totally bogus. However, seeing I am just writing a collection of classes and functions, and there is no int main() function, my compiler keeps throwing fesces at me :( I would like to know what options to pass to my compiler in order for it to just compile the code, but not try to create a single binary from it. (I am not very familiar with the terms linking, compiling, assembling). This is my makefile:
# Hardcoded Makefile
# TODO: Make a nice python script

CC = g++
CFLAGS = `sdl-config --cflags --libs`

OBJS = 	engine.o 	gfx.o 	log.o



r2e : $(OBJS)
	$(CC) $(OBJS) $(CFLAGS)



engine.o : R2e/engine.cpp   R2e/engine.h    R2e/log.h   R2e/state.h R2e/gfx.h
	$(CC) -c R2e/engine.cpp

gfx.o : R2e/gfx.cpp R2e/gfx.h   R2e/engine.h
	$(CC) -c R2e/gfx.cpp

log.o : R2e/log.cpp R2e/log.h
	$(CC) -c R2e/log.cpp



clean :
	rm -f *.o
rob@rob-laptop:~/Development/R2e$ make r2e 
g++ -c R2e/engine.cpp
g++ -c R2e/gfx.cpp
g++ -c R2e/log.cpp
g++ engine.o gfx.o log.o `sdl-config --cflags --libs`
/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [r2e] Error 1

Share this post


Link to post
Share on other sites
Wow, that was a lot easier than I thought! Thanks! I tried looking at gcc --help, and I tried some of the flags, but none of them worked for me. Leaving the whole final call to gcc out... Why didn't I think of that? Thanks again

Share this post


Link to post
Share on other sites
How are you testing the engine you're writing - making sure the code actually works? The compiler will tell you the code compiles but not if it works.

I have my engine project, and another application project that I co-write the engine with (at the moment I'm using a checkers game). That way I can test that what I'm writing in the engine works at the same time as checking that the engine can be used in an actual game.

I realise this wasn't quite the answer you were looking for, but maybe it will solve your problem anyway.

Hope that helps,
Ed

Share this post


Link to post
Share on other sites
Quote:
Original post by c4c0d3m0n
Wow, that was a lot easier than I thought! Thanks! I tried looking at gcc --help, and I tried some of the flags, but none of them worked for me. Leaving the whole final call to gcc out... Why didn't I think of that? Thanks again


Well, actually you're already using the g++ flag to compile only, its "-c", the thing is your r2e target does the linking part, and what you're getting is a link error not a compile error.

Happy Coding.

Share this post


Link to post
Share on other sites
You could have a main that runs tests. That's the least you could do. You really need to be testing this stuff as you write it. Heck, you might actually consider making a game with your engine!

Obligatory game engine link. You are allowed to write a game and an engine at the same time! [smile]

Maybe you could link it as a static lib? That might be cool.

Share this post


Link to post
Share on other sites
That is indeed a very good article. I have my own reason to write this engine. I'm basically writing it because I have no inspiration, I have nothing else to program right now. I've tried writing a nice gamestate manager before, and now I want to write it with some more functionality so it is an "engine". The engine is very very basic, it will just stop me of writing the state manager every time again and all the SDL initialization stuff all the time again. Additionally, it's going to provide me with some resource manager kind of functionality (graphics, sounds, fonts).

Any kind of physics, maths, collision detection or other logic will have to come from the person actually writing the game. It's a good idea to write my own game for this engine though, because I'm sure it will help the development of the engine itself and also catch nasty bugs. However, I'd like to make a start on the sprite/texture-manager before writing a simple Tetris kind of game using the engine.


The static linking sounds very cool. I would have no idea how to do this (frankly, I haven't googled yet either), but this is definately something I'd like to give a try.

Share this post


Link to post
Share on other sites
Quote:
Original post by c4c0d3m0n
The static linking sounds very cool. I would have no idea how to do this (frankly, I haven't googled yet either), but this is definately something I'd like to give a try.



libr2e.a : $(OBJS)
ar -cru libr2e.a $(OBJS)



If I am not mistaken about the flags.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this