g++如何使用make
g++ how to use make?
我有这个生成文件
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)
我的另一个.cpp是
int f( ) noexcept // example function
{
return 2;
}
我的主.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
。
相关文章:
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- mingw32-make 使用"MinGW Makefiles"生成器跟踪 CMAKE 无法将可执行文件链接到对象库
- 如何使用MySQL Connector and Make设置C++项目
- 使用 make 将对象文件放在特定目录中
- 使用 CMake (make) 和 GCC 构建和编译 gSOAP 项目
- 如何在bazel中使用make规则链接库构建
- 有没有办法为 c++ 制作一个 makefile,每次使用 make 命令时都会运行该程序?
- 使用 make 编译多个可执行文件
- 有什么方法可以在 GNU Make 中使用变量作为规则和先决条件?
- 是否可以在 make 调用中使用 BUILD_MODE
- 致命错误:glew.h:使用 make 时没有这样的文件或目录
- 我可以使用 cmake/make 编译我使用的所有且仅编译 cpp/hpp 文件吗?
- 修复了安装 OSRM 时使用"make"命令时的构建问题
- 当删除部分依赖列表时,GNU make 对每个对象文件使用相同的源文件
- 使用 make 命令编译类文件
- 为什么我在使用 Qt creator 用 C 编译代码时出错,但可以使用 make 文件轻松做到这一点
- WSL:make在使用-j时失败
- 使用MINGW-MAKE构建OpenCV 3.3在47%时给出错误2
- 如何在方法中使用 make "using" 关键字以接受它作为类级别
- 指示gnu make只使用静态库