Error in makefile (“no input files”)

前端 未结 2 1954
故里飘歌
故里飘歌 2021-01-28 07:38

This is my absolute first time ever making a makefile, and I\'m really trying to understand the process.

I\'m trying to create a very simple makefile for a C++ project w

2条回答
  •  我在风中等你
    2021-01-28 08:09

    IDIR=include .
    CC=g++
    CFLAGS=-I$(IDIR)
    

    This is wrong. First, for C++ code, use CXX not CC and CXXFLAGS not CFLAGS. Run make -p to understand the builtin rules of your make.

    Then -I$(IDIR) does not "distribute" the -I, and IDIR is never used elsewhere. So I suggest to start your Makefile with:

    CXX=g++
    MY_CXX_LANG_FLAGS= -std=c++11
    MY_CXX_WARN_FLAGS= -Wall -Wextra
    MY_CXX_INCL_FLAGS= -I.  -Iinclude
    MY_CXX_MACRO_FLAGS= -DMYFOO=32
    ### replace with -O2 for a release build below
    MY_CXX_OPTIM_FLAGS= -g 
    CXXFLAGS= $(MY_CXX_LANG_FLAGS) $(MY_CXX_WARN_FLAGS) \
              $(MY_CXX_INCL_FLAGS) $(MY_CXX_MACRO_FLAGS)
    

    I won't improve your Makefile, but I do suggest to upgrade to GNU make version 4 if possible (and compiling make 4.1 from its source code is worthwhile in 2015) for that purpose. If possible enable GUILE scripting in it.

    If you are forced to use make 3.82 debug your Makefile using remake (with -x); if you can afford a make version 4 use its --trace option

    BTW, you might consider using automatic dependencies, that is generating dependencies by passing -M or -MG (etc) flags of g++, see that.

    At last, a simple project for a small program (less than a hundred thousands of source lines) might just put all (a few dozens of) its files in the current directory (then the Makefile could be simpler); your proposed directory structure might be arcane for a simple project (but could worth the pain if you have millions of C++ source lines of code). I've given several simple examples of Makefile, e.g. this & that. And GNU make source code itself has a less complex file tree that what you want.

    BTW, I strongly disagree with the opinions of that answer (which I did upvote, since it is helpful). I don't feel that GNU make is senile, but I regret that, instead of using recent features available on recent versions (4.x) of make, many people prefer to use complex and arcane Makefile generators (like cmake) instead of coding a clever Makefile (for make version 4 specifically).

    At last, you could use other builders, e.g. omake, icmake, ....

提交回复
热议问题