views:

187

answers:

1

So I'm having trouble compiling my application which is using yaml-cpp

I'm including "yaml.h" in my source files (just like the examples in the yaml-cpp wiki) but when I try compiling the application I get the following error:

g++    -c -o entityresourcemanager.o entityresourcemanager.cpp
entityresourcemanager.cpp:2:18: error: yaml.h: No such file or directory
make: *** [entityresourcemanager.o] Error 1

my makefile looks like this:

CC = g++
CFLAGS = -Wall
APPNAME = game
UNAME = uname
OBJECTS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))

mac: $(OBJECTS) 
        $(CC) `pkg-config --cflags --libs sdl` `pkg-config --cflags --libs yaml-cpp`  $(CFLAGS) -o $(APPNAME) $(OBJECTS)

pkg-config --cflags --libs yaml-cpp returns:

-I/usr/local/include/yaml-cpp  -L/usr/local/lib -lyaml-cpp

and yaml.h is indeed located in /usr/local/include/yaml-cpp

Any idea what I could do?

Thanks

+1  A: 

Your default target is "mac" and you have rule how to build it. It depends on object files and you do not have any rules how to build those, so make is using its implicit rules. Those rules do just that:

g++    -c -o entityresourcemanager.o entityresourcemanager.cpp

As you can see there is no -I/usr/local/... part here.

The easiest way to fix that is to change CPPFLAGS and LDFLAGS value globally:

YAML_CFLAGS := $(shell pkg-config --cflags yaml-cpp)
YAML_LDFLAGS := $(shell pkg-config --libs yaml-cpp)
SDL_CFLAGS := $(shell pkg-config --cflags sdl)
SDL_LDFLAGS := $(shell pkg-config --libs sdl)

CPPFLAGS += $(YAML_CFLAGS) $(SDL_CFLAGS)
LDFLAGS += $(YAML_LDFLAGS) $(SDL_LDFLAGS)

mac: $(OBJECTS) 
    $(CXX) -o $(APPNAME) $(OBJECTS) $(LDFLAGS) 

CPPFLAGS value is used by implicit rules that build object files from cpp files, so now compiler should find yaml headers.

Edit: LDFLAGS probably should go after OBJECTS

danadam