I'm having issues getting my Makefile to work for a simple C++ project. The error I am getting is
"fatal-error: no input files"
Here is my project structure:
ROOT
|
|___Makefile
|
|___bin
|
|___src
| |
| |___main.cpp
|
|___include
|
|___GL
| |
| |___glew.h
| |___glfw3.h
|
|___glm
|
|___glm.hpp
And Here is my Makefile:
CC = g++
INC_DIR1 = include/GL
INC_DIR2 = include/glm
SRC_DIR = src
OBJ_DIR = bin
CFLAGS = -c -Wall -I
SRCS = $(SRC_DIR)/main.cpp
OBJS = $(OBJ_DIR)/main.o
DEPS = $(INC_DIR1)/glew.h $(INC_DIR1)/glfw3.h $(INC_DIR2)/glm.hpp
EXECUTABLE = game
all: $(OBJS) $(EXECUTABLE)
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp
$(CC) $(CFLAGS) $< -o $@
$(EXECUTABLE): $(OBJS)
$(CC) $(OBJS) -o $@
$(OBJ_DIR)/main.o: $(DEPS)
I'm not sure if its trying to find .ccp files for the header files or If I set my Makefile up incorrectly. I'm pretty new to Makefiles so any insight would be much appreciated.
Thanks.
So I was able to resolve most of the issues I was having however now I am getting the following error when I try to make my program via command line:
:multiple definition of `main'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../..\libmingw32.a(main.o):main.c:(.tex
t.startup+0x0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../..\libmingw32.a(main.o):main.c:(.tex
t.startup+0xa7): undefined reference to `WinMain@16'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: c:/mingw/b
in/../lib/gcc/mingw32/4.8.1/../../..\libmingw32.a(main.o): bad reloc address 0x2
0 in section `.eh_frame'
collect2.exe: error: ld returned 1 exit status
make: *** [game.exe] Error 1
Below is my Updated Makefile
#Makefile
CC = g++
INC_DIR = include
LIB_DIR = lib
SRC_DIR = src
OBJ_DIR = bin
CFLAGS = -Wall -I $(INC_DIR)
LDFLAGS = -L $(LIB_DIR) -static -lglfw3 -lmingw32
OPTIONS = -std=c++0x -O3
SRCS = $(SRC_DIR)/main.cpp
OBJS = $(OBJ_DIR)/main.o
EXECUTABLE = game.exe
all: $(EXECUTABLE)
$(EXECUTABLE) : $(SRCS)
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
clean:
rm $(EXECUTABLE)
I know the issue is that it is finding two main methods in a file somewhere in my mingw32 library but I am unsure as to how I should go about resolving the error.
Please show the command that was invoked and the exact error you got, cut and pasted. It would have taken me about 1/20th the time to see what was wrong if you'd have done that.
Here's your problem:
CFLAGS = -c -Wall -I
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.cpp
$(CC) $(CFLAGS) $< -o $@
Expanded out, this will run the following command:
g++ -c -Wall -I src/main.cpp -o bin/main.o
The problem here is you've got -I
in your CFLAGS
, with no directory after it. That means that the next word, in this case src/main.cpp
, is taken to be the directory to be added to the include line.
Probably you want something like:
CFLAGS = -c -Wall -I$(INC_DIR1) -I$(INC_DIR2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.