手工制作和自动生成的makefile在windows下失败但在unix上工作

时间:2013-07-29 22:52:29

标签: c netbeans makefile codeblocks

我有一个项目,可以在unix下使用手工制作的基本makefile进行编译,但是不能在windows下使用netbeans或code :: blocks。这显然会使项目非常难以调试。我尝试使用我的手工制作的makefile代替自动生成的makefile,我仍然会得到下面的错误列表。

In file included from Graph.h:7:0,
                 from main.cpp:9:
List.h:37:6: error: expected unqualified-id before ‘delete’
List.h:40:16: error: variable or field ‘printList’ declared void
List.h:40:16: error: ‘FILE’ was not declared in this scope
List.h:40:22: error: ‘out’ was not declared in this scope
List.h:40:32: error: expected primary-expression before ‘L’

我制作的makefile是:

BASE_SOURCES   = Graph.c List.c
BASE_OBJECTS   = Graph.o List.o
HEADERS        = Graph.h List.h
COMPILE        = gcc -c -std=c99 -Wall
LINK           = gcc -o
REMOVE         = rm -f
MEMCHECK       = valgrind --leak-check=full

GraphClient : GraphClient.o $(BASE_OBJECTS)
    $(LINK) GraphClient GraphClient.o $(BASE_OBJECTS)

FindPath.o : FindPath.c $(HEADERS)
    $(COMPILE) FindPath.c

GraphClient.o : GraphClient.c $(HEADERS)
    $(COMPILE) GraphClient.c

$(BASE_OBJECTS) : $(BASE_SOURCES) $(HEADERS)
    $(COMPILE) $(BASE_SOURCES)

clean :
    $(REMOVE) GraphClient GraphClient.o $(BASE_OBJECTS)

checkClient : GraphClient
    $(MEMCHECK) GraphClient

如果有人想要的话,我可以包含netbeans生成的makefile,但我不认为这很重要,因为我的手工制作也无法在windows下工作。对于实际的代码,我认为它真的很重要,因为它在unix下编译?

1 个答案:

答案 0 :(得分:2)

编译头文件时,gcc会报告语法错误。最可能的原因是Linux和Windows之间的一个标准头文件的内容不同。 List.h第37行附近的代码是什么样的?

另请注意,gcc抱怨{40}未在第40行声明FILE。这意味着stdio.h在此之前由另一个头文件包含在Linux上,但未包含在Windows中。