MT4 DLL/TA-LIB链接器错误 这是我第二次尝试C++程序,所以我还在学习。
我正在尝试创建一个DLL来使用Metatrader 4,它使用Visual Studio 2013社区的ta lib技术分析库 但是,当我构建解决方案时,我会遇到以下链接器错误,我不知道如何修复它们MT4 DLL/TA-LIB链接器错误 这是我第二次尝试C++程序,所以我还在学习。,c++,c++11,dll,linker-errors,mt4,C++,C++11,Dll,Linker Errors,Mt4,我正在尝试创建一个DLL来使用Metatrader 4,它使用Visual Studio 2013社区的ta lib技术分析库 但是,当我构建解决方案时,我会遇到以下链接器错误,我不知道如何修复它们 Error 4 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in libc
Error 4 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in libcmt.lib(typinfo.obj) C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\iDEMA\MSVCRT.lib(ti_inst.obj) iDEMA
Error 5 error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in libcmt.lib(typinfo.obj) C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\iDEMA\MSVCRT.lib(ti_inst.obj) iDEMA
Error 2 error LNK2005: _free already defined in libcmt.lib(free.obj) C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\iDEMA\MSVCRT.lib(MSVCR120.dll) iDEMA
Error 3 error LNK2005: _malloc already defined in libcmt.lib(malloc.obj) C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\iDEMA\MSVCRT.lib(MSVCR120.dll) iDEMA
Warning 1 warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\iDEMA\LINK iDEMA
Error 7 error LNK1169: one or more multiply defined symbols found C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\Release\iDEMA.dll iDEMA
Error 6 error LNK2005: _DllMain@12 already defined in uafxcw.lib(dllmodul.obj) C:\Users\Documents\Visual Studio 2013\Projects\iDEMA\iDEMA\* CIL library *(* CIL module *) iDEMA
我的头文件是
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the IDEMA_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// IDEMA_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef IDEMA_EXPORTS
#define IDEMA_API __declspec(dllexport)
#else
#define IDEMA_API __declspec(dllimport)
#endif
#pragma pack(push,1)
struct RateInfo
{
__int64 ctm;
double open;
double low;
double high;
double close;
unsigned __int64 vol_tick;
int spread;
unsigned __int64 vol_real;
};
#pragma pack(pop)
enum ENUM_PRICE
{
PRICE_OPEN,
PRICE_LOW,
PRICE_HIGH,
PRICE_CLOSE
};
// This class is exported from the iDEMA.dll
class IDEMA_API CiDEMA {
public:
CiDEMA(void);
double iDEMA(RateInfo, int, int, int, ENUM_PRICE);
};
extern IDEMA_API int niDEMA;
IDEMA_API int fniDEMA(void);
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include "C:\ta-lib-0.4.0-msvc\ta-lib\c\include\ta_libc.h"
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
我还是不知道如何修复它们
任何帮助都将不胜感激
谢谢。试着像这样包装标题:
extern "C"
{
#include "stdafx.h"
#include "iDEMA.h"
}
#include <stdafx.h>
#include <iDEMA.h>
#包括
#包括
它们看起来在不同的地方。如果没有帮助,请在旧项目中尝试外部“C”(在更新10/10/15之前)
也许你在第一次尝试时已经在路径中添加了一些dll或lib,在“更新10/10/15”之后,你就不再需要它们了
也读一下这个
还有这个
编辑:
如果可能,创建一个新项目。也许,在你的尝试中,你弄糟了什么 尝试像这样包装标题:
extern "C"
{
#include "stdafx.h"
#include "iDEMA.h"
}
#include <stdafx.h>
#include <iDEMA.h>
#包括
#包括
它们看起来在不同的地方。如果没有帮助,请在旧项目中尝试外部“C”(在更新10/10/15之前)
也许你在第一次尝试时已经在路径中添加了一些dll或lib,在“更新10/10/15”之后,你就不再需要它们了
也读一下这个
还有这个
编辑:
如果可能,创建一个新项目。也许,在你的尝试中,你弄糟了什么 尝试像这样包装标题:
extern "C"
{
#include "stdafx.h"
#include "iDEMA.h"
}
#include <stdafx.h>
#include <iDEMA.h>
#包括
#包括
它们看起来在不同的地方。如果没有帮助,请在旧项目中尝试外部“C”(在更新10/10/15之前)
也许你在第一次尝试时已经在路径中添加了一些dll或lib,在“更新10/10/15”之后,你就不再需要它们了
也读一下这个
还有这个
编辑:
如果可能,创建一个新项目。也许,在你的尝试中,你弄糟了什么 尝试像这样包装标题:
extern "C"
{
#include "stdafx.h"
#include "iDEMA.h"
}
#include <stdafx.h>
#include <iDEMA.h>
#包括
#包括
它们看起来在不同的地方。如果没有帮助,请在旧项目中尝试外部“C”(在更新10/10/15之前)
也许你在第一次尝试时已经在路径中添加了一些dll或lib,在“更新10/10/15”之后,你就不再需要它们了
也读一下这个
还有这个
编辑:
如果可能,创建一个新项目。也许,在你的尝试中,你弄糟了什么 在修改了头文件和源文件后,成功地将其链接到链接。以下是最终结果:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the IDEMA_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// IDEMA_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#define WIN32_LEAN_AND_MEAN
#define MT4_EXPFUNC __declspec(dllexport)
#pragma pack(push,1)
struct RateInfo
{
__int64 ctm;
double open;
double low;
double high;
double close;
unsigned __int64 vol_tick;
int spread;
unsigned __int64 vol_real;
};
enum ENUM_PRICE
{
PRICE_OPEN,
PRICE_LOW,
PRICE_HIGH,
PRICE_CLOSE
};
#pragma pack(pop)
// This class is exported from the iDEMA.dll
class MT4_EXPFUNC CiDEMA {
public:
CiDEMA(void);
double iDEMA(RateInfo, int, int, int, ENUM_PRICE);
};
extern MT4_EXPFUNC int niDEMA;
MT4_EXPFUNC int fniDEMA(void);
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include "C:\ta-lib-0.4.0-msvc\ta-lib\c\include\ta_libc.h"
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
//下面的ifdef块是创建宏的标准方法,该宏使导出
//从一个更简单的DLL。此DLL中的所有文件都使用IDEMA_导出进行编译
//在命令行上定义的符号。不应在任何项目上定义此符号
//使用此DLL的。这样,源文件中包含此文件的任何其他项目都可以看到
//IDEMA_API的功能是从DLL导入,而此DLL可以看到符号
//使用此宏定义为正在导出。
#定义WIN32_精益_和_平均值
#定义MT4_EXPFUNC__declspec(dllexport)
#pragma包(推送,1)
结构费率信息
{
__int64 ctm;
双开;
双低;
双高;
双重关闭;
未签名的64卷勾号;
国际传播;
未签名的64 vol_real;
};
枚举枚举价格
{
价格开放,
价格低廉,
价格高,,
收盘价
};
#布拉格语包(流行语)
//此类是从iDEMA.dll导出的
类MT4_EXPFUNC CiDEMA{
公众:
CiDEMA(无效);
双iDEMA(RateInfo,int,int,int,ENUM_PRICE);
};
外部MT4_EXPFUNC int niDEMA;
MT4_EXPFUNC int fniDEMA(无效);
#包括
#包括
#包括
#包括
#包括
#包括
#包括“C:\ta-lib-0.4.0-msvc\ta-lib\C\include\ta_-libc.h”
#布拉格语一次
#如果没有__
#错误“在为PCH包含此文件之前包含'stdafx.h'”
#恩迪夫
#包括“resource.h”//main符号
和源文件:
// iDEMA.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "iDEMA.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using namespace std;
MT4_EXPFUNC double __stdcall iDEMA(const RateInfo* rates, const int rates_total, const int period, const int shift, const ENUM_PRICE applied_price)
{
//---
if (rates == NULL)
{
printf("iDEMA: NULL array\n");
return(0.0);
}
//---
if (rates_total<0 || rates_total<2 * period)
{
printf("iDEMA: wrong rates_total number (%d)\n", rates_total);
return(0.0);
}
//---
if (period<2 || period>100000)
{
printf("iDEMA: wrong period number (%d)\n", period);
return(0.0);
}
//---
if (shift<0 || shift >= rates_total)
{
printf("iDEMA: wrong shift number (%d)\n", shift);
return(0.0);
}
//---
if (applied_price<0 || applied_price>3)
{
printf("iDEMA: wrong applied price (%d)\n", applied_price);
return(0.0);
}
//---
TA_RetCode retCode;
retCode = TA_Initialize();
if (retCode != TA_SUCCESS)
{
printf("TA_LIB initialistion failed (%d)!\n", retCode);
return(0.0);
}
vector<TA_Real> dataArray;
const TA_Real* dataArray_c_pointer = dataArray.data();
// DEMA = ( 2 * EMA(n)) - (EMA(EMA(n)) ), where n= period
for (int nitem = rates_total - 1 - shift - (2 * period); nitem < rates_total - 1 - shift; nitem++)
{
TA_Real value = 0.0;
switch (applied_price)
{
case PRICE_OPEN: value = rates[nitem].open; break;
case PRICE_LOW: value = rates[nitem].low; break;
case PRICE_HIGH: value = rates[nitem].high; break;
case PRICE_CLOSE: value = rates[nitem].close; break;
}
dataArray[nitem] = value;
}
TA_Integer outBegin = 0, outElements = 0;
int beginIndx, endIndx;
beginIndx = endIndx = dataArray.size() - 1;
int array_size = endIndx - beginIndx + 1;
cout << "beginIndx = " << to_string(beginIndx) << endl << "endIndx = " << to_string(endIndx) << endl << "array_size = " << to_string(array_size) << endl;
vector<TA_Real> outDema(array_size, 0.0);
TA_Real* outDema_c_pointer = outDema.data();
retCode = TA_DEMA(beginIndx, endIndx, dataArray_c_pointer, period, &outBegin, &outElements, outDema_c_pointer);
double value = 0.0;
if (retCode == TA_SUCCESS)
{
cout << "outBegin = " << outBegin << " outElements = " << outElements << endl;
int lastElement = outElements - 1;;
cout << "outDema.at(" << to_string(lastElement) << ") = " << to_string(outDema.at(lastElement)) << endl;
delete dataArray_c_pointer;
delete outDema_c_pointer;
value = outDema.at(lastElement);
}
retCode = TA_Shutdown();
return value;
}
//iDEMA.cpp:定义DLL应用程序的导出函数。
//
#包括“stdafx.h”
#包括“iDEMA.h”
#ifdef_调试
#定义新调试\u新
#恩迪夫
使用名称空间std;
MT4\u EXPFUNC double\u stdcall iDEMA(常量费率信息*费率、常量整数费率总计、常量整数期间、常量整数移位、常量枚举价格应用价格)
{
//---
如果(速率==NULL)
{
printf(“iDEMA:NULL数组\n”);
回报率(0.0);
}
//---
if(rates_total在修改了头文件和源文件后成功地将其链接到link。下面是最终结果:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the IDEMA_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// IDEMA_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#define WIN32_LEAN_AND_MEAN
#define MT4_EXPFUNC __declspec(dllexport)
#pragma pack(push,1)
struct RateInfo
{
__int64 ctm;
double open;
double low;
double high;
double close;
unsigned __int64 vol_tick;
int spread;
unsigned __int64 vol_real;
};
enum ENUM_PRICE
{
PRICE_OPEN,
PRICE_LOW,
PRICE_HIGH,
PRICE_CLOSE
};
#pragma pack(pop)
// This class is exported from the iDEMA.dll
class MT4_EXPFUNC CiDEMA {
public:
CiDEMA(void);
double iDEMA(RateInfo, int, int, int, ENUM_PRICE);
};
extern MT4_EXPFUNC int niDEMA;
MT4_EXPFUNC int fniDEMA(void);
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include "C:\ta-lib-0.4.0-msvc\ta-lib\c\include\ta_libc.h"
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
#include "resource.h" // main symbols
//下面的ifdef块是创建宏的标准方法,该宏使导出
//从DLL导出。此DLL中的所有文件都使用IDEMA_导出进行编译
//在命令行上定义的符号。不应在任何项目上定义此符号
//使用此DLL的。通过这种方式,源文件包含此文件的任何其他项目请参见
//IDEMA_API的功能是从DLL导入,而此DLL可以看到符号
//使用此宏定义为正在导出。
#def