C++ 非常简单的应用程序因来自 Eclipse 的“多目标模式”而失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2401976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:22:13  来源:igfitidea点击:

Very simple application fails with "multiple target patterns" from Eclipse

c++eclipsegcccygwinmakefile

提问by Paul Lammertsma

Since I'm more comfortable using Eclipse, I thought I'd try converting my project from Visual Studio. Yesterday I tried a very simple little test. No matter what I try, makefails with "multiple target patterns". (This is similar to this unanswered question.)

因为我更习惯使用 Eclipse,所以我想我会尝试从 Visual Studio 转换我的项目。昨天我尝试了一个非常简单的小测试。无论我尝试什么,make都会因“多个目标模式”而失败。(这类似于这个未回答的问题。)

I have three files:

我有三个文件:

Application.cpp:

应用程序.cpp:

using namespace std;

#include "Window.h"

int main() {
    Window *win = new Window();
    delete &win;
    return 0;
}

Window.h:

窗口.h:

#ifndef WINDOW_H_
#define WINDOW_H_

class Window {
public:
    Window();
    ~Window();
};

#endif

Window.cpp:

窗口.cpp:

#include <cv.h>
#include <highgui.h>

#include "Window.h"

const char* WINDOW_NAME = "MyApp";

Window::Window() {
    cvNamedWindow(WINDOW_NAME, CV_WINDOW_AUTOSIZE);
    cvResizeWindow(WINDOW_NAME, 200, 200);
    cvMoveWindow(WINDOW_NAME, 0, 0);
    int key = 0;
    while (true) {
        key = cvWaitKey(0);
        if (key==27 || cvGetWindowHandle(WINDOW_NAME)==0) {
            break;
        }
    }
}
Window::~Window() {
    cvDestroyWindow(WINDOW_NAME);
}

I have added the following paths to the compiler include path (-I):

我已将以下路径添加到编译器包含路径 ( -I):

"$(OPENCV)/cv/include"
"$(OPENCV)/cxcore/include"
"$(OPENCV)/otherlibs/highgui"

I have added the following libraries to the linker (-l):

我已将以下库添加到链接器 ( -l):

cv
cxcore
highgui

And the following library search path (-L):

以及以下库搜索路径 ( -L):

"$(OPENCV)/lib/"

Eclipse, the compiler and the linker all succeed in including the headers and libraries. I am using the GNU C/C++ compiler & linker from Cygwin.

Eclipse、编译器和链接器都成功地包含了头文件和库。我正在使用 Cygwin 的 GNU C/C++ 编译器和链接器。

When compiling, I get the following makeerror:

编译时,我收到以下make错误:

src/Window.d:1: *** multiple target patterns. Stop.

src/Window.d:1: *** multiple target patterns. Stop.

Window.d contains:

Window.d 包含:

src/Window.d src/Window.o: ../src/Window.cpp \
  C:/Program\ Files/OpenCV/cv/include/cv.h \
  C:/Program\ Files/OpenCV/cxcore/include/cxcore.h \
  C:/Program\ Files/OpenCV/cxcore/include/cxtypes.h \
  C:/Program\ Files/OpenCV/cxcore/include/cxerror.h \
  C:/Program\ Files/OpenCV/cxcore/include/cvver.h \
  C:/Program\ Files/OpenCV/cxcore/include/cxcore.hpp \
  C:/Program\ Files/OpenCV/cv/include/cvtypes.h \
  C:/Program\ Files/OpenCV/cv/include/cv.hpp \
  C:/Program\ Files/OpenCV/cv/include/cvcompat.h \
  C:/Program\ Files/OpenCV/otherlibs/highgui/highgui.h \
  C:/Program\ Files/OpenCV/cxcore/include/cxcore.h ../src/Constants.h \
  ../src/Window.h
C:/Program\ Files/OpenCV/cv/include/cv.h:
C:/Program\ Files/OpenCV/cxcore/include/cxcore.h:
C:/Program\ Files/OpenCV/cxcore/include/cxtypes.h:
C:/Program\ Files/OpenCV/cxcore/include/cxerror.h:
C:/Program\ Files/OpenCV/cxcore/include/cvver.h:
C:/Program\ Files/OpenCV/cxcore/include/cxcore.hpp:
C:/Program\ Files/OpenCV/cv/include/cvtypes.h:
C:/Program\ Files/OpenCV/cv/include/cv.hpp:
C:/Program\ Files/OpenCV/cv/include/cvcompat.h:
C:/Program\ Files/OpenCV/otherlibs/highgui/highgui.h:
C:/Program\ Files/OpenCV/cxcore/include/cxcore.h:
../src/Window.h:

I tried removing all OpenCV headers from Window.d (from line 2 onwards), but the error remains. Also, I've updated Eclipse and OpenCV, all to no avail.

我尝试从 Window.d(从第 2 行开始)删除所有 OpenCV 标头,但错误仍然存​​在。另外,我已经更新了 Eclipse 和 OpenCV,但都无济于事。

Do you have any ideas worth trying? I'm willing to try anything!

你有什么值得尝试的想法吗?我愿意尝试任何事情!

回答by James McNellis

Are you working from a Cygwin installation?

您是在 Cygwin 安装中工作吗?

I've seen this problem before using Cygwin--basically, makesees the :in the path and thinks it is another target definition, hence the error.

我在使用 Cygwin 之前见过这个问题——基本上,make看到:路径中的 并认为它是另一个目标定义,因此出现错误。

If you are working from a Cygwin installation, you might try replacing the c:/with /cygdrive/c/. If not, you might try using relative paths or using a network mount and see if that fixes it.

如果您是从Cygwin安装工作,你可以尝试更换c:/使用/cygdrive/c/。如果没有,您可以尝试使用相对路径或使用网络安装,看看是否能解决问题。

回答by marco

according to other internet sources this is related to a problem that cygwin make has with windows path names, specially the c:. For me it workes fine with setting relative paths instead.

根据其他互联网资源,这与 cygwin make 的 Windows 路径名问题有关,特别是 c:。对我来说,它可以很好地设置相对路径。

e.g. if you have something like

例如,如果你有类似的东西

proj/mymodule/headers/afile.h
proj/mymodule/source/abc/afile.c

just add ../mymodule/headers/as include path in the project configuration for the compiler this will find the header afile.hand will generate make files with relative path. (compiler command will have the statement -I../mymodule/headers/)

只需../mymodule/headers/在编译器的项目配置中添加为包含路径,这将找到标题afile.h并生成具有相对路径的 make 文件。(编译器命令会有语句-I../mymodule/headers/

looks like execution directory is always the project base directory.

看起来执行目录始终是项目基目录。

回答by barcaleiku

On Cygwin, GNU make version 3.81-1 delivered by the default setup program doesn't work with the automatic header file dependencies, generated by the compilers. The error message you will see because of this bug will look something like this:

在 Cygwin 上,默认安装程序提供的 GNU make 版本 3.81-1 不适用于编译器生成的自动头文件依赖项。由于此错误,您将看到的错误消息如下所示:

Here are two suggested fixes: - Try to obtain the previous version (3.80) - Obtain a fixed 3.81 version, for example from http://www.cmake.org/files/cygwin/make.exe

这里有两个建议的修复: - 尝试获取以前的版本 (3.80) - 获取固定的 3.81 版本,例如从 http://www.cmake.org/files/cygwin/make.exe

src: https://projects.coin-or.org/BuildTools/wiki/current-issues

源代码:https: //projects.coin-or.org/BuildTools/wiki/current-issues

Simply replace the make file in your "C:\cygwin\bin\" folder (or wherever cygwin is installed) with the "fixed" make file mentioned above.

只需将“C:\cygwin\bin\”文件夹(或安装 cygwin 的任何地方)中的 make 文件替换为上面提到的“固定”make 文件。

回答by Crow Soup

Looks like there is a simple way to solve this. Just change the "Current Builder" from "GNU Make Builder" to "CDT Internal Builder" in Project properties->C/C++ Builder->Tool Chain Editor->Current Builder will do.

看起来有一个简单的方法可以解决这个问题。只需在项目属性->C/C++ Builder->Tool Chain Editor->Current Builder 中将“Current Builder”从“GNU Make Builder”更改为“CDT Internal Builder”即可。

To me, this problem is caused by the automatically generated "XXX.d" dependency files in Debug directory (or release :), which were generated by gcc -MF as a side-effect to gcc -c. But GNU make obviously forgot to add quotations around file names when -MF.

对我来说,这个问题是由 Debug 目录(或 release :) 中自动生成的“XXX.d”依赖文件引起的,这些文件是由 gcc -MF 生成的,作为 gcc -c 的副作用。但是 GNU make 显然忘记在 -MF 时在文件名周围添加引号。

"CDT Internal Builder" does not use makefile nor GNU make at all. Eclipse manage the build process itself.

“CDT Internal Builder”根本不使用 makefile 或 GNU make。Eclipse 自己管理构建过程。

If you insist to use GNU make, this doesn't work

如果你坚持使用 GNU make,这是行不通的

回答by Thagomizer

I also had the problem of multiple target patterns reported by make when using eclipse on windows/cygwin. I solved the problem as suggested above by using only relative paths. I didn't realize that I had absolute paths, but when I specified an include directory using the project directory, eclipse expanded it into the full path.

在 windows/cygwin 上使用 eclipse 时,我也遇到了由 make 报告的多个目标模式的问题。我只使用相对路径解决了上面建议的问题。我没有意识到我有绝对路径,但是当我使用项目目录指定包含目录时,eclipse 将其扩展为完整路径。

For instance, if you add a path relative to the workspace, eclipse generates ""${workspace_loc:/include}"" which will expand to something starting with "c:\". This is why it was happening in my case.

例如,如果您添加相对于工作区的路径,eclipse 会生成“${workspace_loc:/include}””,它将扩展为以“c:\”开头的内容。这就是为什么它发生在我的情况下。

I simply replaced the complex string above with "../../include" and it solved my problem.

我只是用“../../include”替换了上面的复杂字符串,它解决了我的问题。

回答by duckduckgo

You can also delete *.d files under output folders and then build

也可以删除output文件夹下的*.d文件,然后build

Debug/src/

回答by tzg

I'm working in the Cygwin environment, on Windows 7 (64bit), using Eclipse Kepler CDT for C++.

我在 Windows 7(64 位)上的 Cygwin 环境中工作,使用 Eclipse Kepler CDT for C++。

In Eclipse, goto

在 Eclipse 中,转到

Project --> Properties --> C++ Builder --> Settings --> Tool Settings Tab

Cygwin C++ Compiler --> Includes

项目 --> 属性 --> C++ Builder --> 设置 --> 工具设置选项卡

Cygwin C++ 编译器 --> 包括

In the Include paths (-I) add 2 paths: "C:\cygwin64\usr\include\libxml2"

在包含路径 (-I) 中添加 2 个路径:“C:\cygwin64\usr\include\libxml2”

and "/cygdrive/c\cygwin64\usr\include\libxml2"

“/cygdrive/c\cygwin64\usr\include\libxml2”

回答by Brick

One change that worked for me (I use Cygwin and SSH terminal into an SVN server in parallel) was to delete the .dfiles. When I called the make -f makefilefrom Cygwin, it broke something. I usually compile from the Putty terminal, and after deleting the .dfiles from my project it stopped complaining about the multiple targets.

对我有用的一项更改(我使用 Cygwin 和 SSH 终端并行进入 SVN 服务器)是删除.d文件。当我make -f makefile从 Cygwin调用 时,它破坏了某些东西。我通常从 Putty 终端编译,.d从我的项目中删除文件后,它不再抱怨多个目标。

回答by FLEMIN JOSE

The error "multiple target patterns. Stop." will occur because src/Window.d have the paths generated by compiler in windows platform as:

错误“多个目标模式。停止。” 会发生,因为 src/Window.d 有编译器在 windows 平台中生成的路径为:

C:/Program\ Files/OpenCV/cv/include/cv.h \ C:/Program\ Files/OpenCV/cxcore/include/cxcore.h \ C:/Program\ Files/OpenCV/cxcore/include/cxtypes.h \ C:/Program\ Files/OpenCV/cxcore/include/cxerror.h \

C:/Program\ Files/OpenCV/cv/include/cv.h \ C:/Program\ Files/OpenCV/cxcore/include/cxcore.h \ C:/Program\ Files/OpenCV/cxcore/include/cxtypes.h \ C:/Program\ Files/OpenCV/cxcore/include/cxerror.h \

If you import this project into Eclipse in Linux platform, I would recommend you to give a clean build so that next build generates the path in Linux format as:

如果您将此项目导入到 Linux 平台的 Eclipse 中,我建议您进行干净构建,以便下次构建生成 Linux 格式的路径:

/home/user/OpenCV/cv/include/cv.h \ /home/user/OpenCV/cxcore/include/cxcore.h \ /home/user/OpenCV/cxcore/include/cxtypes.h \ /home/user/OpenCV/cxcore/include/cxerror.h \

/home/user/OpenCV/cv/include/cv.h \ /home/user/OpenCV/cxcore/include/cxcore.h \ /home/user/OpenCV/cxcore/include/cxtypes.h \ /home/user/OpenCV/cxcore/include/cxerror.h \

The same is applicable, if you are using cygwin. The path format in cygwin is linux like format /cygdrive/c/instead of C:/

如果您使用的是 cygwin,这同样适用。cygwin 中的路径格式是类似 linux 的格式/cygdrive/c/而不是C:/