我想编译这个小程序:
#include <iostream>
#include <SDL.h>
using namespace std;
int main() {
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
cout << "SDL init failed" << endl;
return 1;
}
cout << "Hello World" << endl;
return 0;
}
我可以成功地做到:
g++ -o SDL_basic SDL_basic.cpp -I/opt/local/include/SDL2/ -l SDL2 -L/opt/local/lib/
我花了最后一个小时来尝试修改我通常用来做的文件:
CXX=g++
INC=-I/opt/local/include/SDL2/
LIBSEARCHPATH=-L/opt/local/lib/
LIBS=-l SDL2
OBJECTS=$(PROJECT).o
PROJECT=SDL_basic
$(PROJECT) : $(OBJECTS)
${CXX} $(CPFLAGS) $(OBJECTS) -o $@ ${INC} ${LIBSEARCHPATH} ${LIBS}
.cpp.o :
${CXX} -c ${CPFLAGS} $? ${INC} ${LIBSEARCHPATH} ${LIBS}
clean :
rm -f $(OBJECTS)
运行make终于可以正常运行了,但是如果我对.cpp进行了少量更改后第二次运行它,则会收到以下警告:
clang: warning: -lSDL2: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/opt/local/lib/' [-Wunused-command-line-argument]
因此我的问题。这对我在makefile中所做的有意义吗?
之后,参数$ {INC} $ {LIBSEARCHPATH} $ {LIBS}确实属于.cpp.o:和$(PROJECT):$(OBJECTS)之后吗?我希望有人能帮助我。 非常感谢! F