我正在編寫必須從mpusbapi.dll文件中導入其某些函數的類。不幸的是,當我嘗試包括ActuatorControl.h在主文件中,我得到了LNK2005已經定義的錯誤,在VS 2015中使用Microchip的mpusbapi.h會產生「LNK2005已定義」錯誤
Error LNK2005
"unsigned long (__cdecl* MPUSBGetConfigurationDescriptor)(void *,unsigned char,void *,unsigned long,unsigned long *)" ([email protected]@[email protected])
already defined in ActuatorControl.obj
Linear Actuator
C:\Users\Edward Harsono\Desktop\Linear Actuator\Linear Actuator\Linear Actuator.obj
1
從mpusbapi.dll獲得該功能的其餘部分得到了相同的信息。我已經包含了mpusbapi.h和ActuatorControl.h的警衛。我在Visual Studio 2015中編寫了此代碼。
mpusbapi.h和mpusbapi.dll從Microchip Technology Incorporated獲得。
有人可以幫助我嗎?我已經上了好幾個小時了。這是我的代碼。
的main.cpp
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <windows.h>
#include "ActuatorControl.h"
int main()
{
ActuatorControl x;
return 0;
}
ActuatorControl.h
#pragma once
#ifndef _ActuatorControl_H_
#define _ActuatorControl_H_
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <windows.h>
#include <Dbt.h>
#include <tchar.h>
#include "mpusbapi.h"
class ActuatorControl {
private:
//----------------Global variables used in this application--------------------------------
public:
ActuatorControl();
~ActuatorControl();
};
#endif
ActuatorControl.cpp
#include "ActuatorControl.h"
ActuatorControl::ActuatorControl() {
HMODULE DLL = LoadLibrary(L"mpusbapi.dll");
if (DLL) {
MPUSBGetDLLVersion = (DWORD(*)(void)) GetProcAddress(DLL, "_MPUSBGetDLLVersion");
}
}
ActuatorControl::~ActuatorControl() {
}
請編輯您的問題以提供[mcve]。 –
我編輯了它,幷包含一個可驗證的例子。它可以被編譯,並會給你錯誤 –
我在'ActuatorControl.h'看到一個問題一個標題不應該有'#包括「stdafx.h」' – drescherjm