问题
I have been enjoying the luxury of coding with an IDE that writes my makefile's for me, Iv decided that I have been 'short cutting' for far to long, so I have read a few manuals and watched a few videos on makefiles and have a makefile semi-done, the only trouble that I'm having is I'm not sure how to link libraries.
CPPS := $(shell ls src/*cpp)
TEMP := $(subst src/,obj/,$(CPPS))
OBJS := $(subst .cpp,.o,$(TEMP))
HEADERS := $(shell ls inc/*.h)
EXEC := bin/testfile
all: $(EXEC)
$(EXEC) : $(OBJS) $(HEADERS)
g++ -I inc/ $(OBJS) -o $(EXEC) -lSDL -lGLU
$(EXEC)
obj/%.o: src/%.cpp
g++ -Wall -I inc/ -c $< -o $@
ps: just incase I am saying the wrong thing when I say 'Library flags' I mean -lSDL -lGLU
etc...
Wherever I put them they dont seem to work.
This is the error I get when I insert the lib flags,
make: *** [bin/testfile] Error 255
The Error 255 is produced by make as a result of its command shell not being able to find a command for a particular rule.
If i dont include them I get standard 'undefined' messages.
Any help with this would be greatly appreciated! Thank you
回答1:
It looks like you are trying to run your executable after you have built it?
It that case the problem is that you don't have your current directory on the PATH; so make can't find $(EXEC)
.
You should probably just do ./$(EXEC)
to run it directly.
And you should move executing the program to a different (PHONY
) target, so that you can do just the build step on its own, and run when $(EXEC)
doesn't need to be built.
(I'm assuming the lack of tabs is just stackoverflow formatting, as otherwise make
would be complaining).
来源:https://stackoverflow.com/questions/10086607/creating-my-own-makefile-error-255