Makefile troubles

Started by
14 comments, last by Kwizatz 15 years, 7 months ago
I'm getting a little more hardcore into my work environment (Vim, makefiles, etc.) and I just can't seem to get gcc to recognize SDL. I put SDL's include folder in gcc's include folder and I now have an SDL folder right next to GL in minGW\include. It can't find the SDL folder. I think the problem is it doesn't expect it to be there. I'll put SDL.h in the include folder and it's findable. Anything in the GL folder is findable. How to I show it how to find SDL's folder? (And preferably a solution that doesn't involve me writing the path to it in every make file, and for every additional library I use.)
Advertisement
SDL includes an app to return the locations and flags required to find and correctly compile. The commands are:
$ sdl-config --cflags$ sdl-config --libs

On my system, this produces:
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT-lSDL -lpthread


For a Makefile you would do something like this:
CFLAGS=-O2 -W -Wall -pedanticLIBS=-lGL -lGLU -lglutSDL_CFLAGS := $(shell sdl-config --cflags)SDL_LDFLAGS := $(shell sdl-config --libs)CPPFLAGS=$(CFLAGS) $(SDL_CFLAGS)LDFLAGS=$(LIBS) $(SDL_LDFLAGS)
Isn't "$" a Linux thing?

Anyway, DOS returned that sdl-config was unrecognized. Basically, I got the normal errors with that added.


What OS are you using? How did you install SDL?
Windows XP. I installed it by copying the files to the right places. I followed Lazy Foo's tutorial to make sure I didn't miss any thing.
http://lazyfoo.net/SDL_tutorials/lesson01/windows/mingw/index.php

Might part of the problem be that I installed MinGW in a place other than c:\MinGW?
Sorry, my mistake, that is for Linux makefiles. I should have noticed the mention of minGW.

You mentioned that you placed the include folder in minGW\include folder, which means you have the SDL headers in minGW\include\SDL. But you didn't mention if you had copied the SDL library files over, as specified by Lazy Foo's item #2. According to the tutorial you need to copy the files in SDL\lib folder to minGW\lib.

If thats not the problem then maybe you could post the error messages you receive when you try to compile.
For your viewing pleasures (warning: long):

C:\WINDOWS\system32\cmd.exe /c makeg++ main.cpp -lmingw32 -lSDLmain -lSDL -mwindowsIn file included from main.cpp:51:Graphics.h:24:21: SDL/SDL.h: No such file or directoryGraphics.h:27:28: SDL/SDL_opengl.h: No such file or directoryGraphics.h:29:23: SOIL/SOIL.h: No such file or directoryIn file included from Graphics.h:32,                 from main.cpp:51:Controller.h:19: error: ISO C++ forbids declaration of `SDL_Joystick' with no typeController.h:19: error: expected `;' before '*' tokenController.h:20: error: `SDL_Event' does not name a typeController.h: In constructor `Controller::Controller()':Controller.h:31: error: `SDL_GetKeyState' undeclared (first use this function)Controller.h:31: error: (Each undeclared identifier is reported only once for each function it appears in.)Controller.h:33: error: `joystick' undeclared (first use this function)Controller.h:33: error: `SDL_JoystickOpen' undeclared (first use this function)Controller.h:36: error: `SDL_GetError' undeclared (first use this function)Controller.h: In member function `bool Controller::eventToProcess()':Controller.h:50: error: `events' undeclared (first use this function)Controller.h:50: error: `SDL_PollEvent' undeclared (first use this function)Controller.h: In member function `bool Controller::userWantsQuit()':Controller.h:55: error: `events' undeclared (first use this function)Controller.h:55: error: `SDL_QUIT' undeclared (first use this function)Controller.h:55: error: `SDLK_ESCAPE' undeclared (first use this function)Controller.h: In member function `bool Controller::processMouse()':Controller.h:64: error: `events' undeclared (first use this function)Controller.h:64: error: `SDL_MOUSEBUTTONUP' undeclared (first use this function)Controller.h:67: error: `SDL_BUTTON_LEFT' undeclared (first use this function)Controller.h:70: error: `SDL_MOUSEBUTTONDOWN' undeclared (first use this function)Controller.h: In destructor `Controller::~Controller()':Controller.h:82: error: `SDL_JoystickOpened' undeclared (first use this function)Controller.h:83: error: `joystick' undeclared (first use this function)Controller.h:83: error: `SDL_JoystickClose' undeclared (first use this function)In file included from main.cpp:51:Graphics.h: At global scope:Graphics.h:46: error: `GLuint' does not name a typeGraphics.h:49: error: expected constructor, destructor, or type conversion before '*' tokenGraphics.h:49: error: expected `,' or `;' before '*' tokenGraphics.h:56: error: `HGLRC' does not name a typeGraphics.h:57: error: `HDC' does not name a typeGraphics.h:58: error: `HWND' does not name a typeGraphics.h:59: error: `HINSTANCE' does not name a typeGraphics.h: In function `bool getGL_Error()':Graphics.h:74: error: `GLenum' undeclared (first use this function)Graphics.h:74: error: expected `;' before "error"Graphics.h:76: error: `error' undeclared (first use this function)Graphics.h:76: error: `glGetError' undeclared (first use this function)Graphics.h:76: error: `GL_NO_ERROR' undeclared (first use this function)Graphics.h:85: error: `GL_INVALID_ENUM' undeclared (first use this function)Graphics.h:89: error: `GL_INVALID_VALUE' undeclared (first use this function)Graphics.h:93: error: `GL_INVALID_OPERATION' undeclared (first use this function)Graphics.h:97: error: `GL_STACK_OVERFLOW' undeclared (first use this function)Graphics.h:101: error: `GL_STACK_UNDERFLOW' undeclared (first use this function)Graphics.h:105: error: `GL_OUT_OF_MEMORY' undeclared (first use this function)Graphics.h: In function `void finish()':Graphics.h:123: error: `SDL_Quit' undeclared (first use this function)Graphics.h: At global scope:Graphics.h:127: error: `GLvoid' does not name a typeGraphics.h:147: error: `LRESULT' does not name a typeGraphics.h: In function `void init_GL()':Graphics.h:215: error: `glClearColor' undeclared (first use this function)Graphics.h:218: error: `glClearDepth' undeclared (first use this function)Graphics.h:220: error: `GL_LEQUAL' undeclared (first use this function)Graphics.h:220: error: `glDepthFunc' undeclared (first use this function)Graphics.h:222: error: `GL_POLYGON_SMOOTH' undeclared (first use this function)Graphics.h:222: error: `glEnable' undeclared (first use this function)Graphics.h:223: error: `GL_LINE_SMOOTH' undeclared (first use this function)Graphics.h:224: error: `GL_SMOOTH' undeclared (first use this function)Graphics.h:224: error: `glShadeModel' undeclared (first use this function)Graphics.h:231: error: `GL_PERSPECTIVE_CORRECTION_HINT' undeclared (first use this function)Graphics.h:231: error: `GL_NICEST' undeclared (first use this function)Graphics.h:231: error: `glHint' undeclared (first use this function)Graphics.h:232: error: `GL_POLYGON_SMOOTH_HINT' undeclared (first use this function)Graphics.h:234: error: `GL_PROJECTION' undeclared (first use this function)Graphics.h:234: error: `glMatrixMode' undeclared (first use this function)Graphics.h:235: error: `glLoadIdentity' undeclared (first use this function)Graphics.h:236: error: `glOrtho' undeclared (first use this function)Graphics.h:238: error: `GL_MODELVIEW' undeclared (first use this function)Graphics.h: In function `bool initSDL_GL(int, int, int)':Graphics.h:267: error: `SDL_INIT_EVERYTHING' undeclared (first use this function)Graphics.h:267: error: `SDL_Init' undeclared (first use this function)Graphics.h:269: error: `SDL_GetError' undeclared (first use this function)Graphics.h:275: error: `SDL_OPENGL' undeclared (first use this function)Graphics.h:275: error: `SDL_SetVideoMode' undeclared (first use this function)Graphics.h: In function `void draw_GL()':Graphics.h:312: error: `glLoadIdentity' undeclared (first use this function)Graphics.h:314: error: `glFlush' undeclared (first use this function)Graphics.h:315: error: `SDL_GL_SwapBuffers' undeclared (first use this function)Graphics.h:316: error: `GL_COLOR_BUFFER_BIT' undeclared (first use this function)Graphics.h:316: error: `GL_DEPTH_BUFFER_BIT' undeclared (first use this function)Graphics.h:316: error: `glClear' undeclared (first use this function)Graphics.h: At global scope:Graphics.h:322: error: `GLuint' does not name a typeGraphics.h: In function `void drawRect(GLfloat, GLfloat, bool)':Graphics.h:370: error: `GL_QUADS' undeclared (first use this function)Graphics.h:370: error: `glBegin' undeclared (first use this function)Graphics.h:377: error: `glVertex2f' undeclared (first use this function)Graphics.h:384: error: `glEnd' undeclared (first use this function)Graphics.h:387: error: `glLoadIdentity' undeclared (first use this function)Graphics.h: At global scope:Graphics.h:400: error: variable or field `drawTex' declared voidGraphics.h:400: error: `drawTex' declared as an `inline' variableGraphics.h:400: error: `GLuint' was not declared in this scopeGraphics.h:400: error: expected primary-expression before "w"Graphics.h:400: error: expected primary-expression before "h"Graphics.h:401: error: expected primary-expression before "bool"Graphics.h:402: error: initializer expression list treated as compound expressionGraphics.h:402: error: expected `,' or `;' before '{' tokenGraphics.h:423: error: expected `,' or `...' before '*' tokenGraphics.h:424: error: ISO C++ forbids declaration of `SDL_Color' with no typeGraphics.h: In function `Uint32 colorToUint32(int)':Graphics.h:430: error: `color' undeclared (first use this function)Graphics.h: In function `void clearScreen()':Graphics.h:441: error: `SDL_Rect' undeclared (first use this function)Graphics.h:441: error: expected `;' before "srnClear"Graphics.h:442: error: `srnClear' undeclared (first use this function)Graphics.h:444: error: `Uint16' has not been declaredGraphics.h:445: error: `Uint16' has not been declaredGraphics.h:447: error: `screen' undeclared (first use this function)Graphics.h:447: error: `SDL_MapRGB' undeclared (first use this function)Graphics.h:447: error: `SDL_FillRect' undeclared (first use this function)In file included from main.cpp:52:time.h:8:27: SDL/SDL_Timer.h: No such file or directoryIn file included from main.cpp:52:time.h: In constructor `Timer::Timer(Uint32)':time.h:28: error: `SDL_GetTicks' undeclared (first use this function)time.h: In member function `Uint32 Timer::set()':time.h:48: error: `SDL_GetTicks' undeclared (first use this function)time.h: In function `Uint32 getTicks()':time.h:60: error: `SDL_GetTicks' undeclared (first use this function)In file included from Character.h:11,                 from main.cpp:54:ScreenOb.h: In member function `virtual void ScreenOb::draw(GLfloat, GLfloat) const':ScreenOb.h:53: error: `glTranslatef' undeclared (first use this function)ScreenOb.h:55: error: `glRotatef' undeclared (first use this function)In file included from Character.h:74,                 from main.cpp:54:Box.h: In member function `virtual void Box::draw()':Box.h:27: error: `GL_LINE_LOOP' undeclared (first use this function)Box.h:27: error: `glBegin' undeclared (first use this function)Box.h:28: error: `glVertex2f' undeclared (first use this function)Box.h:32: error: `glEnd' undeclared (first use this function)Box.h:34: error: `glLoadIdentity' undeclared (first use this function)In file included from main.cpp:55:Player.h: At global scope:Player.h:11: error: `GLuint' does not name a typeIn file included from Player.h:16,                 from main.cpp:55:Bullet.h: In member function `virtual void Bullet::draw()':Bullet.h:34: error: `GL_TRIANGLE_STRIP' undeclared (first use this function)Bullet.h:34: error: `glBegin' undeclared (first use this function)Bullet.h:35: error: `glColor4fv' undeclared (first use this function)Bullet.h:37: error: `glVertex2f' undeclared (first use this function)Bullet.h:40: error: `glEnd' undeclared (first use this function)Bullet.h:42: error: `glLoadIdentity' undeclared (first use this function)In file included from main.cpp:55:Player.h: In constructor `Player::Player()':Player.h:33: error: `player_texture' undeclared (first use this function)Player.h:34: error: `loadImage' undeclared (first use this function)Player.h: In member function `virtual void Player::draw()':Player.h:39: error: `GL_TEXTURE_2D' undeclared (first use this function)Player.h:39: error: `glEnable' undeclared (first use this function)Player.h:43: error: `player_texture' undeclared (first use this function)Player.h:43: error: `drawTex' cannot be used as a functionIn file included from main.cpp:56:Map.h: At global scope:Map.h:6: error: `GLuint' does not name a typeMap.h:16: error: `GLuint' does not name a typeIn file included from main.cpp:56:Map.h:24:3: warning: no newline at end of filemain.cpp: In function `int main(int, char**)':main.cpp:70: error: `GL_TEXTURE_ENV' undeclared (first use this function)main.cpp:70: error: `GL_TEXTURE_ENV_MODE' undeclared (first use this function)main.cpp:70: error: `GL_MODULATE' undeclared (first use this function)main.cpp:70: error: `glTexEnvf' undeclared (first use this function)make: *** [Bounce] Error 1shell returned 2Hit any key to close this window...


Do note that when I use my IDE (CodeBlocks), everything's fine, except somehow I'm linking something wrong with OpenGL, but I only hear a complaint when I use SOIL (Simple OpenGL Image Library). The problem can probably be narrowed down to my lack of understanding of make files.

Thanks a lot for helping me out with this.
Based on the lazy foo page you gave, it appears you are using the command line version of MinGW. I installed it to see the setup and successfully compiled the sample code given in the tutorial.

I'm assuming that you are able to compile the sample program from the tutorial, so it is likely your makefile causing the problem. Please post the makefile.
Actually, I am not able to compile the example.

C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\SDL testing>g++ -o myprogram.exe mysource.cpp -lmingw32 -lSDLmain -lSDLmysource.cpp:9:21: SDL\SDL.h: No such file or directorymysource.cpp: In function `int main(int, char**)':mysource.cpp:14: error: `SDL_INIT_EVERYTHING' undeclared (first use this function)mysource.cpp:14: error: (Each undeclared identifier is reported only once for each function it appears in.)mysource.cpp:14: error: `SDL_Init' undeclared (first use this function)mysource.cpp:17: error: `SDL_Quit' undeclared (first use this function)C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\SDL testing>


Here's the makefile for the project I was doing:

Bounce :	g++ main.cpp -lmingw32 -lSDLmain -lSDL -mwindows 


Not much to really look at, I know.
try

g++ main.cpp -ISDL -lmingw32 -lSDLmain -lSDL -mwindows

or

g++ main.cpp -Ic:/mingw/include/SDL -lmingw32 -lSDLmain -lSDL -mwindows

Though, you should really separate compilation and linking into 2 separate steps.

This topic is closed to new replies.

Advertisement