2013-06-27 61 views
-2

我正在为我的程序构建一个make文件。 主要是:twitServer.cpp 及其使用:Command.h Client.h编译和链接C++程序 - make文件

我建立了一个make文件,它似乎不工作。 你能帮我弄清楚吗?

twitServer: twitServer.o Command.o Client.o 
    g++ -Wall -o twitServer.o Command.o Client.o twitServer 

twitServer.o: twitServer.cpp Command.h Client.h 
    g++ -c -Wall twitServer.cpp 

Command.o: Command.cpp Command.h 
    g++ -c -Wall Command.cpp 

Client.o: Client.cpp Client.h 
    g++ -c -Wall Client.cpp 

clean: 
    rm twitServer Client.o Command.o Client.o 

我的错误是: G ++:twitServer:没有这样的文件或目录

虽然我得到了这一切的文件: Client.cpp Client.o Command.h的Makefile twitServer.cpp Client.h Command.cpp Command.o的Makefile〜twitServer.o

+0

请详细说明'似乎没有工作'。你有错误吗? –

+0

您确定您在命令开头处有TAB特殊字符吗? (在g ++之前)。当您尝试运行该生成文件时,收到的错误消息是什么? – ondrejdee

+0

这是错误:g ++:twitServer:没有这样的文件或目录 –

回答

1

这个:

g++ -Wall -o twitServer.o Command.o Client.o twitServer 

是错的。你不希望编译器输出到twitServer.o链接twitServer文件,你呢?这两个应该翻转,像这样:

g++ -Wall -o twitServer Command.o Client.o twitServer.o 
+0

谢谢,但现在修复后,我试图运行该程序,并得到:twitServer:command not found –

+0

@fgfjhgrjrerjhm阅读我对其他答案的评论,还是我需要在这里重复一遍? – 2013-06-27 07:37:07

1

更改-o标志的位置:

twitServer: twitServer.o Command.o Client.o 
    g++ -Wall twitServer.o Command.o Client.o -o twitServer 
+0

谢谢,但现在我得到:twitServer:命令未找到 试图运行程序 –

+2

@fgfjhgrjrerjhm '。/ twitServer' – 2013-06-27 07:35:30

+0

这是为什么?我怎样才能使它运行没有./? –