Home > Back-end >  At the end of Makefile can not find file
At the end of Makefile can not find file

Time:09-15

Makefile in learning c + +, recently made a simple example, but have been looking for drawing file, display hit (using the cygwin on Windows 7 32 bit analog Linux environment, make the version is the GNU make 4.3),
Makefile directory as follows, including demo. CPP is compiled file,

Demo. CPP code is very simple, as follows,
 # include & lt; Iostream> 
#include
#include

using namespace std;

Int main ()
{
Cout<& lt;" This is the demo!" }

Among them, the common. H files in the demo. CPP file directory on a list of common folder, as shown in the following


The makefile file content is as follows:
 INCDIR=-i../common/# - I/home/ShenTao/repository/c_cpp/common/common h 
LIB=- lthread

CXX=g + + - STD=c + + 11
CXXFLAG=- Wall - g - O2
TARGET=demo
The OBJECT=demo. O

$(ALL) : $(OBJECT)
$(CXX) $$(CXXFLAG) $^ (INCDIR) -o $@ $(LIB)
% *. O: % *. CPP
$(CXX) $$(CXXFLAG) - c (INCDIR) $@ $$^ - o (LIB)

PHONY: clean

Clean:
Rm - rf $(TARGET) $(OBJS)
@ echo "o linked and compiled files... "

But always say can't find common. H file

Excuse me what reason be? Thank you very much!

CodePudding user response:

INCDIR variables at the back of the blank space on either side of the equal sign to remove try again

INCDIR=-i../common

CodePudding user response:

reference 1st floor SDGHCHJ response:
INCDIR variables at the back of the blank space on either side of the equal sign out try again

INCDIR=-i../common


Thank you for your answer, but still won't do ~

CodePudding user response:

With the full path, for yourself

CodePudding user response:

reference 4 floor SDGHCHJ response:
with the full path, oneself fumble
used the full path, also not line

CodePudding user response:

#include

Don't look for the library files?

#include
# include "is common. H"

The two should be still there

CodePudding user response:




Wrote a manually, compile ok, pay attention to the second picture - i../common/, you haven't print, check your Makefile format

CodePudding user response:

references 9 f soulsoul_god response:



Wrote a manually, compile ok, pay attention to the second picture - i../common/, you haven't print, check your Makefile format

Thank you for your advice!!!!!!
Q: your tests in a Linux environment?
I tried several times, and found a strange phenomenon, I put all the header files from common and demo. In the same directory, CPP this kind of circumstance is not, in theory at this moment do not need to specify the search path!
In addition, in order to prevent the effects of Makefile format, I use notepad + + to create a new empty file, use utf-8 format, rewriting the Makefile, running show that there are still can't find the mistakes above,
But in the same Makefile, I - I.../common/added to CXX variables, you can compile a success, as shown in the following:
 LIB=- lthread 

CXX=g + + - STD=c + + 11 - i../common/
CXXFLAG=- Wall - g - O2
TARGET=demo
The OBJECT=demo. O

$(ALL) : $(OBJECT)
$(CXX) $$^ (CXXFLAG) -o $@ $(LIB)
% *. O: % *. CPP
$(CXX) $(CXXFLAG) - c $@ $$^ - o (LIB)

Clean:
Rm - rf $(TARGET) $(OBJS)
@ echo "o linked and compiled files... "

So I feel or Windows + cygwin is probably the environmental cause,,,

CodePudding user response:

references to the tenth floor taotaost response:
Quote: references 9 f soulsoul_god response:




Wrote a manually, compile ok, pay attention to the second picture - i../common/, you haven't print, check your Makefile format

Thank you for your advice!!!!!!
Q: your tests in a Linux environment?
I tried several times, and found a strange phenomenon, I put all the header files from common and demo. In the same directory, CPP this kind of circumstance is not, in theory at this moment do not need to specify the search path!
In addition, in order to prevent the effects of Makefile format, I use notepad + + to create a new empty file, use utf-8 format, rewriting the Makefile, running show that there are still can't find the mistakes above,
But in the same Makefile, I - I.../common/added to CXX variables, you can compile a success, as shown in the following:
 LIB=- lthread 

CXX=g + + - STD=c + + 11 - i../common/
CXXFLAG=- Wall - g - O2
TARGET=demo
The OBJECT=demo. O

$(ALL) : $(OBJECT)
$(CXX) $$^ (CXXFLAG) -o $@ $(LIB)
% *. O: % *. CPP
$(CXX) $(CXXFLAG) - c $@ $$^ - o (LIB)

Clean:
Rm - rf $(TARGET) $(OBJS)
@ echo "o linked and compiled files... "

So I feel or Windows + cygwin is probably the environmental cause,,,


First of all, the first question, if you put the common h in the demo. CPP under the same path, is the demo. CPP to modify into such # include "common. J h,"
I am under Linux compiled,
A Makefile can echo, try to add a few echo, print out the information you want to see,
  • Related