【发布时间】:2016-02-16 13:34:09
【问题描述】:
我知道有几个这样的问题,到目前为止我没有找到答案似乎可以解决我的问题。
我正在使用 Eclipse。
我在 main 函数中编写了一些代码,它运行良好。 然后我在 main 中使用了一个外部函数,现在我得到了一些有趣的错误。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <random>
#include <ctime>
#include <cstdlib>
using namespace std;
using namespace cv;
void createSaltandPepper();
int main(int argc, char** argv) {
createSaltandPepper();
return 0;
}
不,因为我不想再举一个广泛的例子,这里是函数的外部:
void createSaltandPepper() {
//mycode
}
至少看起来不是拼写错误。
但是,错误是:
make all
make: *** No rule to make target 'SaltPepper.o', needed by 'Display'.
如果我的函数被称为 createSaltandPepper,我确实想知道为什么它会尝试创建一个名为 SaltPepper.o 的 tagert。
有人可以帮帮我吗?
编辑:我没有刻意创建一个makefile,正如我所说的我正在使用eclipse。 同样,只要代码在主函数内部而不是在 createSaltandPepper() 内部,它就可以正常工作。 我的文件叫DisplayImage.cpp,上面的代码在这个文件里,包括函数createSaltandPepper(); 该文件中仅有的两个函数是 main 函数和 createSaltandPepper(); 项目中没有其他源文件。
如果我觉得自己很愚蠢,我很抱歉:我是一名 Java 程序员,对 makefile 等一无所知。
看这个截图:
我现在创建了一个新项目并将我的旧文件添加到其中,这次将其命名为 Display.cpp
“build all”导致 subdir.mk 出现错误,内容如下:
subdir.mk:18: recipe for target 'Display.o' failed
make: *** [Display.o] Error 1
构建的完整错误信息如下:
make all
Building file: ../Display.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0-std=c++11 -MMD -MP -MF"Display.d" -MT"Display.d" -o"Display.o" "../Display.cpp"
subdir.mk:18: recipe for target 'Display.o' failed
g++: error: argument to ‘-fmessage-length=’ should be a non-negative integer
make: *** [Display.o] Error 1
更新
我切换到 Netbeans。 现在可以了。
【问题讨论】:
-
你有没有push it?你必须把它推得很好。
-
这与 C++ 无关。你的makefile有问题。学习如何使用 C++ 开发的第 1 步:学习识别来自编译器的实际 C++ 错误消息,而不是您的构建系统。
-
@user1862770 Sam 是对的,错误与 C++ 无关。即使您没有自己创建 makefile,您仍然有一个,并且您必须对其进行调试。提示:SaltPepper.c 是否已添加到您的 Eclipse 项目中?
-
那么你有什么文件做?不要让人猜。显然,该函数未在
main.cpp或您在此处引用的任何内容中定义,那么它在哪里定义 ? -
您的
createSaltAndPepper函数位于何处?在哪个文件中?
标签: c++ compiler-errors target