WinForm应用程序:以新形式捕获视频流.错误LNK2005! [英] WinForm application : Capture videostream in a new form. Error LNK2005!

查看:73
本文介绍了WinForm应用程序:以新形式捕获视频流.错误LNK2005!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想意识到这件事:
Form1(Button_Click)-> Form2(Butto_Click)->来自网络摄像头的视频预览.

我已经可以:
Form1(Button_Click)->视频预览.

我很容易在form1下创建form2.h,在form2下创建CamShow.h.
但是我遇到了这样的错误消息:
错误LNK2005:公共:__thiscall WebcamShow :: CamShow :: CamShow(void)"(?? 0CamShow @ WebcamShow @@ QAE @ XZ)已经在Form2.obj中定义. (和我在CamShow中声明的所有方法都一样)

CamShow.h的代码:

Hello,

I want to realize this thing:
Form1(Button_Click)-> Form2(Butto_Click)-> Video preview from webcam.

what I already can:
Form1(Button_Click)-> Video Preview.

I easily make form2.h under form1 and CamShow.h under form2.
But i got this error which says:
error LNK2005: "public: __thiscall WebcamShow::CamShow::CamShow(void)" (??0CamShow@WebcamShow@@QAE@XZ) is already in Form2.obj defined.
(and all the methods i declared in CamShow are mentioned just the same)

Codes for CamShow.h:

#include <DShow.h>
#include <Windows.h>
#include <comdef.h>

#define WM_GRAPHNOTIFY  WM_APP+1
enum VIDEOSTATUS {Stopped, Paused, Running, Init};
namespace WebcamShow
{
	public class CamShow
	{
	public: CamShow(); 
		~CamShow();

	public:		HRESULT CamShow::InitComLib();
			HRESULT CamShow::CaptureVideo(int);
			......
	public: 
			IGraphBuilder			*pGraphBuilder;
			ICaptureGraphBuilder		*pCGB;
			ICaptureGraphBuilder2		*pCGB2;
			IVideoWindow			*pVW;

			IMediaControl			*pMC;
			IMediaEventEx			*pME;
                        ......
			
	};

	CamShow::CamShow()
	{		
			pGraphBuilder				= NULL; 
			pCGB					= NULL;
			pCGB2					= NULL;
			pVW					= NULL;

			pMC					= NULL;
			pME					= NULL;

			......
	}
	CamShow::~CamShow() {}

	HRESULT CamShow::InitComLib()
	{
		HRESULT hr = NULL;
		hr = CoInitialize(NULL);
		return hr;
	}
        ......	 



表格1:



Form1:

#pragma once
#include "Form2.h"
......

和Form2:

And Form2:

#pragma once
#include "CamShow.h"
......



我认为问题在于重复的声明.我已经阅读了有关此错误的msdn解释,对此我不太了解.
我该如何解决?



i think the problem is about duplicated declarations. And i''ve read the msdn explaination for this error, which i don''t quite understand.
How can I solve this?

Thanks!!!

推荐答案

您的第一个代码块 CamShow.h 是一个头文件,不仅包含声明,而且还包含将每次包含文件时进行编译.因此,您将获得多次编译的相同代码,并存储在不同的目标文件中.链接器然后生成错误.

您应将代码段(构造函数,析构函数,函数)移到自己的源文件 CamShow.cpp 中.您可以选择将短函数声明为inline.
Your your first code block CamShow.h is a header file containing not only declarations but also code that will be compiled each time the file is included. So you will get the same code compiled multiple times and stored in different object files. The linker then generates the error.

You should move the code sections (constructor, destructor, functions) into an own source file CamShow.cpp. Optionally you may declare short functions as inline.


这篇关于WinForm应用程序:以新形式捕获视频流.错误LNK2005!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆