I’m trying to distribute a little software written on C++ on Linux that uses openGL and SFML. I’m trying to provide the sfml libraries and headers with my code in order to avoid the installation of sfml (people who will use it have no root access, but they will have all the openGL needed stuff installed).
My file hierarchy is as follows:
- lib/ >> here goes all the sfml libraries (.so files)
- Makefile >> later I show the code
- src/ >> Here goes program and sfml sources
- myfiles.h, myfiles.cpp >> all them compile and work allright with the sfml libraries installed at /usr/lib
- SFML/ >> here goes all the sfml headers, has some subfolders
Here’s my Makefile:
EJECUTABLE = app
MODULOS = src/main.o src/Handbapp.o src/Camera.o src/Light.o src/Scene.o src/Graphics.o src/Window.o src/Model.o src/Court.o src/Player.o src/Primitives.o src/Path.o
CC = g++
LIBDIR = ./lib
INCDIR = ./src
LIBS = -lsfml-window -lsfml-system -lGLU
LDFLAGS = -L$(LIBDIR) -I$(INCDIR)
CFLAGS = -v -Wl,-rpath,$(LIBDIR)
$(EJECUTABLE): clean $(MODULOS)
$(CC) $(CFLAGS) -o $(EJECUTABLE) $(LDFLAGS) $(MODULOS) $(LIBS)
rm -f $(MODULOS)
clean:
rm -f $(MODULOS) $(EJECUTABLE)
When I run make in a PC (Ubuntu 11.10) with sfml installed in /usr/lib it all goes well, if I do in one that doesn’t have it installed it says:
...
g++ -c -o src/main.o src/main.cpp
In file included from src/main.h:18:0,
from src/main.cpp:10:
src/Handbapp.h:17:44: fatal error: SFML/Window.hpp: File or directory doesn't exist
Compilation finished.
make: *** [src/main.o] Error 1
Here’s a piece of code showing the include on Handbapp.h:
...
#ifndef HANDBAPP_H
#define HANDBAPP_H
// Espacio de nombres
using namespace std;
// Librerias
#include <GL/gl.h> // OpenGL
#include <GL/glu.h> // Utilidades OpenGL
#include <SFML/Window.hpp> // Ventanas SFML <- LINE 17
#include <SFML/System.hpp> // SFML
I’ve tried making #include “whatever/Window.hpp”,changing src/SFML folder name for whatever and not using the -I option on the linker, but src/SFML/Window.hpp (and other sfml headers) have include lines like that #include < SFML/Window/Whatever.hpp >, so I need them to search at the path I specify.
Am I missing something? I guess it’s an error with my Makefile, but I don’t have so much experience with it…
Thanks in advance!
You need to put
-I$(INCDIR)intoCPPFLAGS, notLDFLAGS. Then it will be picked up by the built-in rule for compilation of individual object files.You should also rename
CFLAGStoCXXFLAGSandCCtoCXX.CCandCFLAGSare for C source files, not C++ source files.You should not have
$(EJECUTABLE)depend onclean, and you should not executerm -f $(MODULOS)after the link command. Those things defeat the purpose of a Makefile, which is to recompile only what is necessary, not the whole program every single time.