[英]g++ how to use make?
我有这个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)
我的other.cpp是
int f( ) noexcept // example function
{
return 2;
}
我的main.cpp是
int main( int, char** )
{
f( );
return 0;
}
所以,很显然,当我运行make depend
,它只是增加了一条线,说#DO NOT DELETE
。 但是,在编译时,当我运行make
,我得到了main.cpp的此错误: 'f' was not declared in this scope
。 我想我在这里错过了一些大事。 谁能解释为什么它不能编译以及我应该怎么做?
这与您的Makefile无关。
编译器的错误消息是不言自明的。 在C ++中,必须在使用函数之前声明它们。
添加适当的声明:
int f() noexcept;
到您的main.cpp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.