我正在运行 Lubuntu 12.10。我的 make 文件名为 makefile
,如下所示:
all: SquaresTesting.o Vector2d.o
clang -o SquaresTesting SquaresTesting.o
SpringTesting.o: SquaresTesting.cpp
clang -c SquaresTesting.cpp
Vector2d.o: Vector2d.cpp Vector2d.h
clang -c Vector2d.cpp
我与该文件位于同一目录中,但是当我执行 make
时,它会运行 g++ -c -o SquaresTesting.o SquaresTesting.cpp
(有四个空格在 g++ 和 -c 之间;我从来没有做过那样的事情)。似乎更改没有保存。我在想要么 make 崩溃了,要么我的编辑器 Geany 搞砸了,要么文件系统很奇怪,要么我的 SSD 损坏了。
最佳答案
您的编辑器可能有问题,或者您的文件系统可能很奇怪,或者您的 SSD 可能已损坏,但我通常发现,当某些事情无法正常工作时,问题通常是我犯了一个错误:-)。
在这种情况下,您输错了目标:
SpringTesting.o: SquaresTesting.cpp
您已经告诉 make 这个规则将创建 SpringTesting.o
。但是 make 正试图找到一种制作 SquaresTesting.o
的方法。由于您没有构建 SquaresTesting.o
的规则,make 尝试找到一个,它确实找到了一个:有一个内置规则可以从一个构建任何 .o
.cpp
,那里恰好有一个 SquaresTesting.cpp
。
因为 C++ 编译器的默认配置是 g++
,所以它就是这样使用的。
如果您将目标固定为:
SquaresTesting.o: SquaresTesting.cpp
你应该准备好了。当然,您也可以利用 make 的内置规则;您的整个 makefile 可以写成:
CXX = clang
all: SquaresTesting
SquaresTesting: SquaresTesting.o Vector2d.o
我在这里假设您也想链接 Vector2d.o
,尽管您的 makefile 没有显示这一点。
关于linux - Make 正在运行旧的/损坏的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16889966/