0

I'm trying to resolve an unresolved external (link2019 error).There were already some posts on this issue and i try them, but I still could not figure it out.

The error is caused by my CreateFtdcMdApi function ( right?) but my understanding is that this is "resolved".

// testTraderApi.cpp : 定义控制台应用程序的入口点。  
//  
#include "MdSpi.h"  
#include <iostream>
// UserApi对象  
CThostFtdcMdApi* pUserApi = NULL;

// 配置参数  
char FRONT_ADDR[] = "tcp://asp-sim2-md1.financial-trading-platform.com:26213";      // 前置地址  
TThostFtdcBrokerIDType  BROKER_ID = "***";              // 经纪公司代码  
TThostFtdcInvestorIDType INVESTOR_ID = "0***";          // 投资者代码  
TThostFtdcPasswordType  PASSWORD = "*****";         // 用户密码  
char *ppInstrumentID[] = { "***", "***" };            // 行情订阅列表  
int iInstrumentID = 2;                                  // 行情订阅数量  

// 请求编号  
int iRequestID = 0;

void main(void)
{
    // 初始化UserApi  
    char file = 'F';
    pUserApi = CThostFtdcMdApi::CreateFtdcMdApi();          // 创建UserApi  
    CThostFtdcMdSpi* pUserSpi = new CMdSpi();
    pUserApi->RegisterSpi(pUserSpi);                     // 注册事件类  
    pUserApi->RegisterFront(FRONT_ADDR);                 // connect  
    pUserApi->Init();

    pUserApi->Join();
    //  pUserApi->Release();  
}

I truncated the code a bit, because it is verbose.

class MD_API_EXPORT CThostFtdcMdApi
{
public:
    ///创建MdApi
    ///@param pszFlowPath 存贮订阅信息文件的目录,默认为当前目录
    ///@return 创建出的UserApi
    ///modify for udp marketdata
    static CThostFtdcMdApi *CreateFtdcMdApi(const char *pszFlowPath = "", const bool bIsUsingUdp=false, const bool bIsMulticast=false);

    ///获取API的版本信息
    ///@retrun 获取到的版本号
    static const char *GetApiVersion();
    }

Error:

 1>------ Build started: Project: challenges, Configuration: Debug Win32 ------
1>challenges.obj : error LNK2019: unresolved external symbol "public: static class CThostFtdcMdApi * __cdecl CThostFtdcMdApi::CreateFtdcMdApi(char const *,bool,bool)" (?CreateFtdcMdApi@CThostFtdcMdApi@@SAPAV1@PBD_N1@Z) referenced in function _main
1>d:\documents\visual studio 2013\Projects\challenges\Debug\challenges.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
leppie
  • 115,091
  • 17
  • 196
  • 297
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Werner Henze Jul 14 '15 at 12:40
  • If that is all your code, then the Compiler is right. Or where do you see the implementation of CThostFtdcMdApi::CreateFtdcMdApi? – Werner Henze Jul 14 '15 at 12:41
  • Because it is a api which was already implemented and built, I add its lib(static library ) as well as dll in my project. So I thought there might be something wrong with how I link the lib file and dll. – user3913071 Jul 19 '15 at 14:42
  • I'm going to guess that you're linking against the library that exports 64 bit pointers (for whatever reason). The exported symbol is `?CreateFtdcMdApi@CThostFtdcMdApi@@SAPEAV1@PEBD_N1@Z` (note the difference, that one has pointers tagged `__ptr64`), hence the link error. Solution is to use a library with 32 bit pointers (?) or ask developers to fix this issue. – user703016 Sep 08 '15 at 02:23
  • You are correct! I changed original project the default setting of 32 bit into 64 bit , the link problem disappeared. thanks a lot! – user3913071 Sep 17 '15 at 15:53

0 Answers0