为什么这个生成文件不能正确编译?
Why doesn't this Makefile compile correctly?
我有以下Makefile:
CC=g++
CFLAGS=-c -pedantic -std=c++11 -lglfw -lGL -lGLU -lX11 -lXxf86vm -lXrandr -lpthread -lXi
all: Set GLDrawableGraph Edge Graph Play main
Set: Set.cpp Set.h
$(CC) $(CFLAGS) -o Set Set.cpp
GLDrawableGraph: GLDrawableGraph.cpp GLDrawableGraph.h Edge.h Graph.h
$(CC) $(CFLAGS) -o GLDrawableGraph GLDrawableGraph.cpp
Edge: Edge.cpp Edge.h
$(CC) $(CFLAGS) -o Edge Edge.cpp
Graph: Graph.cpp GLDrawableGraph.h Edge.h Graph.h Play.h
$(CC) $(CFLAGS) -o Graph Graph.cpp
Play: Play.cpp GLDrawableGraph.h Edge.h Graph.h Play.h
$(CC) $(CFLAGS) -o Play Play.cpp
main: main.cpp GLDrawableGraph.o Edge.o Graph.o Play.o GLDrawableGraph.h Edge.h Graph.h Play.h Set.o Set.h
$(CC) $(CFLAGS) -o main main.cpp GLDrawableGraph.cpp Edge.cpp Graph.cpp Play.cpp Set.cpp
得到如下输出:
GLDrawableGraph.cpp:95:10: error: ‘p’ does not name a type
auto p=nodes.find(nodenumber);
^
GLDrawableGraph.cpp:96:8: error: ‘p’ was not declared in this scope
if(p==nodes.end()) throw std::string("Tried to color nonexistant vertex");
^
GLDrawableGraph.cpp:97:5: error: ‘p’ was not declared in this scope
p->second.color=col;
^
GLDrawableGraph.cpp: In member function ‘void DrawableGraph::DrawGraph(GLFWwindow*) const’:
GLDrawableGraph.cpp:140:15: error: ISO C++ forbids declaration of ‘e’ with no type [-fpermissive]
for(auto &e : edges) {
^
GLDrawableGraph.cpp:140:19: error: range-based ‘for’ loops are not allowed in C++98 mode
for(auto &e : edges) {
^
GLDrawableGraph.cpp:141:18: error: request for member ‘first’ in ‘e’, which is of non-class type ‘int’
int i1=e.first.first;
^
GLDrawableGraph.cpp:142:18: error: request for member ‘first’ in ‘e’, which is of non-class type ‘int’
int i2=e.first.second;
^
GLDrawableGraph.cpp:151:28: error: request for member ‘second’ in ‘e’, which is of non-class type ‘int’
RGB rgb=RGBColor(e.second.color);
^
GLDrawableGraph.cpp:158:15: error: ISO C++ forbids declaration of ‘p’ with no type [-fpermissive]
for(auto &p : nodes) {
^
GLDrawableGraph.cpp:158:19: error: range-based ‘for’ loops are not allowed in C++98 mode
for(auto &p : nodes) {
^
GLDrawableGraph.cpp:159:26: error: request for member ‘second’ in ‘p’, which is of non-class type ‘int’
float xx=float(p.second.x-R.l)/(R.r-R.l)*1.8-0.9;
^
GLDrawableGraph.cpp:160:26: error: request for member ‘second’ in ‘p’, which is of non-class type ‘int’
float yy=float(p.second.y-R.b)/(R.t-R.b)*1.8-0.9;
我认为这些错误来自c++11与常规c++的差异,但我已经给出了-std=c++11选项,它仍然不起作用
您的makefile依赖项不正确。发生的事情是,它使用内置规则编译您的项目,因此您的标志不适用,编译器不识别c++ 11 auto
关键字。试着用make -r
编译禁用内置规则,看看会发生什么。
你可能想要这样的东西:
CXX := g++
CPPLAGS := -Wall -Wextra
CXXFLAGS := -std=c++11
LDLIBS := -lglfw -lGL -lGLU -lX11 -lXxf86vm -lXrandr -lpthread -lXi
all : main
main : main.o GLDrawableGraph.o Edge.o Graph.o Play.o Set.o
${CXX} -o $@ $^ ${LDLIBS}
%.o : %.cpp # also auto-generates dependencies
${CXX} -c -o $@ ${CPPLAGS} ${CXXFLAGS} -MD -MP -MF ${@:.o=.d} $<
-include $(wildcard *.d) # include auto-generated dependencies
相关文章:
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的 EnumWindowProc 不能用 C 语言编译?
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 为什么通过指针编译时不能分配 const 初始化
- std::variant<>::get() 不能使用 Apple LLVM 10.0 编译
- 为什么使用 std::vector 的代码不能编译,但使用 std::unique_ptr 如果没有 noexcept
- 我不能用C++编译Xcode库
- 返回实例变量的c++方法可以访问变量中的数据,但不能更改它,但在编译时不会生成错误
- 为什么引用不能与编译时函数一起使用?
- 为什么我不能编译这个在Cygwin的Visual Studio中编写的C++文件?
- 为什么一个简单的"Hello World"风格的程序不能用Turbo C++编译?
- 为什么我不能编译这个简单的线程测试?
- C++程序使用 mingw 在 Linux 上交叉编译在 MSy2 中工作,但不能直接在 Windows 中工作
- 此模板函数在哪里生成?可以通过g++编译,但不能在Visual Studio中编译
- 当 pkg-config 不能解决 opencv 'undefined reference'编译问题时,如何解决它?
- 没有返回类型的静态函数可以通过Windows上的编译,但不能传递Linux上的编译
- 警告:不能解析.gnu_debugdata部分;LZMA支持在编译时被禁用
- 为什么 --string::end() 可以编译,而 --string.size() 不能编译?
- lower_bound()函数不能在调试模式下编译
- QT-不能使用外部库进行交叉编译