[英]g++ how to use make?
I have this makefile 我有这个makefile
CC = g++
CFLAGS = -std=c++14 -Wall -Wpedantic -g
PROG = a
OBJS = other.o main.o
SRCS = other.cpp main.cpp
a: $(OBJS)
$(CC) $(CFLAGS) -o $(PROG) $(OBJS)
.cpp.o:
$(CC) $(CFLAGS) -c $*.cpp
clean:
$(RM) -f $(OBJS) $(PROG)
depend:
makedepend -- $(CFLAGS) -- $(SRCS)
My other.cpp is 我的other.cpp是
int f( ) noexcept // example function
{
return 2;
}
My main.cpp is 我的main.cpp是
int main( int, char** )
{
f( );
return 0;
}
So, obviously, When I run make depend
, it only adds a line that says #DO NOT DELETE
. 所以,很显然,当我运行make depend
,它只是增加了一条线,说#DO NOT DELETE
。 However, upon compilation, when i run just make
, i get this error for main.cpp: 'f' was not declared in this scope
. 但是,在编译时,当我运行make
,我得到了main.cpp的此错误: 'f' was not declared in this scope
。 I think I'm missing something big here. 我想我在这里错过了一些大事。 Can anyone explain why this doesn't compile and what I should do? 谁能解释为什么它不能编译以及我应该怎么做?
This has nothing to do with your Makefile. 这与您的Makefile无关。
The compiler's error message is self-explanatory. 编译器的错误消息是不言自明的。 Functions must be declared before they are used, in C++. 在C ++中,必须在使用函数之前声明它们。
Add a proper declaration: 添加适当的声明:
int f() noexcept;
To your main.cpp
. 到您的main.cpp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.