简体   繁体   English

在makefile中使用path包含源文件

[英]include source files using path in makefile

I have one directory called MAKE and two sub directory's source and header. 我有一个名为MAKE的目录,还有两个子目录的源和标头。 source contains cpp files and header contains one header file which is included in all three cpp files. 源包含cpp文件,标头包含一个标头文件,该标头文件包含在所有三个cpp文件中。 I am trying to create a make file. 我正在尝试创建一个make文件。 i am trying to access the source and header files from the directories. 我试图从目录访问源文件和头文件。 my current directory is MAKE(where my make file is present). 我当前的目录是MAKE(其中包含我的make文件)。

I am getting error as NO rule to target. 我遇到错误,因为没有规则可以定位。 Stop Where am i going wrong 停止我要去哪里错了

    CC = g++
    INC_SOURCE = -I/home/abhiskekkumar/Desktop/VINEETH/Make/source/
    INC_DEST =  -I/home/abhiskekkumar/Desktop/VINEETH/Make/header
    SOURCE = $(shell echo *.cpp)
    HEADER = $(shell echo *.h)
    OBJECT = $(SOURCE:.cpp=.o)
    TARGET = output

    EXEC: $(TARGET)
            ./output
    $(TARGET): $(OBJECT)
            $(CC) $(INC_SOURCE) $(INC_DEST) -o $(TARGET) $(OBJECT)

Step 1: we write a makefile that does nothing, but does it correctly. 步骤1:我们编写一个不执行任何操作但正确执行的makefile。

nothing:
    @:

We must test this, and get it working perfectly before we proceed. 我们必须对此进行测试,并使其完全正常运行,然后再继续。

Step 2: we generate a list of source files, and print it out so that we know that it's correct. 步骤2:我们生成源文件列表,然后将其打印出来,以便我们知道它是正确的。

SOURCE = $(wildcard source/*.cpp)
$(info $(SOURCE))

nothing:
    @:

We must test this, and get it working perfectly before we proceed. 我们必须对此进行测试,并使其完全正常运行,然后再继续。

Step 3: we decide where we want the object files to go (eg MAKE/ , MAKE/source/ , or somewhere else). 步骤3:确定目标文件的存放位置(例如MAKE/MAKE/source/或其他位置)。

Try this, post a comment with the results, and we'll proceed. 尝试此操作,对结果发表评论,我们将继续。

 CC = g++
 TARGET = vineeth

 CFLAGS   = -Wall

 LINKER   = g++ -o


SRCDIR   = source
HEADDIR  = header
OBJDIR   = obj
BINDIR   = bin

SOURCES  := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(HEADDIR)/*.h)
OBJECTS  := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)


$(BINDIR)/$(TARGET): $(OBJECTS)
     $(LINKER) $@ $(LFLAGS) $(OBJECTS)
     @echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
     @$(CC) $(CFLAGS) -c $< -o $@
     @echo "Compiled "$<" successfully!"

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

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