LNK2005 Redefinition Error on using CLI --already defined LNK2005 error Pin
I have a native-C++header Unmanaged.h and cpp file Unmanaged.cpp that I need to use with C#. So I am using C++ Interop to use the native files in a managed C++.NET project(CLI) and then reusing the C++.Net project in C#. The name of my managed C++ file is Managed.cpp
I am geting about 40 of the below error(similar error) for each function or variable or object I use in the header file.
error LNK2005: "class CHardwareDelegate11 * pDeckLinkInput1" (?pDelegate11@@3PEAVpDeckLinkInput1@@EA) already defined in Project.obj
Here's how my files look like--
***************Unmanaged.h*********I am not including the whole code.**********
#pragma unmanaged
#pragma once //This should work to make it defined only once
#ifndef BLACKMAGIC_H
#define BLACKMAGIC_H //This should also work to make it defined only once
IDeckLinkInput* pDeckLinkInput1 =NULL; /********************* These variables also generate redefined error***/
IDeckLinkOutput* pDeckLinkOutput1=NULL ; /********************* These variables also generate redefined error***/
class CHardwareDelegate1 : public IDeckLinkVideoOutputCallback, public IDeckLinkInputCallback
{
//variables
//Functions
}
class Data{
int frametoCapture[40];
}
//Class Objects declared here. /********************* These class objects also generate redefined error***/
//Variables Declared here /********************* These variables also generate redefined error***/
#endif
***************Unmanaged.cpp*********I am not including the whole code.**********
#pragma once
#pragma unmanaged
#ifndef Unmanaged_CPP
#define Unmanaged_CPP
//#include "stdafx.h" //Uncommenting commenting makes no difference.
#include "Unmanaged.h"
#include "Unmanaged.h" //Including Unmanaged.h twice gets no error from the compiler. Only including it in the C++.NET file creates error
#include
#include
using namespace std;
#pragma unmanaged
static int SettopBoxCount;
Data Box[12];
int Data::frametoCapture[]={1,4,6,10,14,17,20,22,25,27,31,34,6+30,30+10,30+14,30+17,20+30,22+30,25+30,27+30,1+60,4+60,6+60,10+60,14+60,17+60,20+60,22+60,25+60,27+60,1+90,4+90,6+90,10+90,14+90,17+90,20+90,22+90,25+90,27+90,1+120,4+120,6+120,10+120,14+120,17+120,20+120,22+120,25+120,27+120};
//All class functions and variables defined below.
#endif
*************************Managed.cpp**************************This is the file in which error occurs************
#pragma once
#pragma managed //This makes no difference if its set to unmanaged or managed.
//#include "Unmanaged.h" ///////////////////////////////This is the line which causes the redefinition error///////////////
All these files are in the same CLR project. The Unmanaged.cpp file option is set not to use the CLR runtime. The Managed.cpp file is set to use the CLR runtime. All the files in the project and the project itself is set not to use precompiled headers. I am working in Visual Studio 2008.
What is causing the error. This is so strange. Please help.
Bookmarks