[英]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.