简体   繁体   English

项目“无输入文件”的根目录中的Makefile

[英]Makefile in the Root Directory of a Project “no Input Files”

I'm having issues getting my Makefile to work for a simple C++ project. 我在使Makefile可以用于简单的C ++项目时遇到问题。 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: 这是我的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. 我不确定它是否试图为头文件查找.ccp文件,或者我是否将Makefile设置不正确。 I'm pretty new to Makefiles so any insight would be much appreciated. 我对Makefiles很陌生,所以任何见解都将不胜感激。

Thanks. 谢谢。

EDIT: 编辑:

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

#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. 我知道问题是它正在mingw32库的某个文件中找到两个主要方法,但是我不确定应该如何解决该错误。

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. 如果您这样做的话,大约要花我1/20的时间才能知道出什么问题了。

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. 这里的问题是您的CFLAGS-I ,其后没有目录。 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. 这意味着下一个单词(在本例中为src/main.cpp )被视为要添加到包含行的目录。

Probably you want something like: 可能您想要这样的东西:

CFLAGS = -c -Wall -I$(INC_DIR1) -I$(INC_DIR2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM