Question

I have been reading a book on SFML game development and they use unique_ptr's. And to use them I know that I must use the -std=c++11 flag when compiling, however I have been having issues doing this with a Makefile. Below is a copy of my Makefile:

flags = -lsfml-graphics -lsfml-window -lsfml-system

main: main.cpp texture_holder.o
    g++ main.cpp texture_holder.o -o Run $(flags) -std=c++11

texture_holder: texture_holder.cpp texture_holder.h
    g++ texture_holder.cpp -c -std=c++11

.PHONY: clean
clean:
    rm *.o Run

When just typing make I get errors about unique_ptr not being a member of std. But what I can't figure out, is that when I type make texture_holder texture_holder.cpp does compile just fine then running make builds the application. Do I have something ordered wrong or am I missing anything? If it helps, I can attach the code that I am using, but like I said, it builds just fine when I build the texture_holder target first.

Was it helpful?

Solution

You have wrong rule for texture_holder.o, it should be this:

texture_holder.o: texture_holder.cpp texture_holder.h
        g++ texture_holder.cpp -c -std=c++11

Ie. including the .o extension.


What happens with your question's version is, when you do make texture_holder, you execute that particular rule, which does not actually create corresponding file texture_holder, it creates texture_holder.o, because well, that's what the commend produces. The texture_holder rule is effectively a phony rule, similar to main and clean (and btw, you should add main to .PHONY too).

If you make main, then to create texture_holder.o, make uses implicit rule (because there is no explicit one), which uses different compile command.

OTHER TIPS

You have a rule for making texture_holder, not texture_holder.o. The rule for main will attempt to make texture_holder.o using the default compilation rule, not your special one. The default rule won't specify -std=c++11, hence the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top