C 中调用DLL的问题 undefined reference to 'InitSMGPAPI’
程序源码 :
#include <stdio.h>
#include "smgpapi.h "
#include "smgpdef.h "
#define RECV_MSG_TIME_OUT2 /* Seconds */
static DeliverResp g_DeliverResp;
int main(void)
{
/* Local Vars */
int nRetCode;
/* Call API InitSMGPAPI*/
/* If Your Config File Not In Current Dir Or Config Dir Please */
/* All Dir And File Name */
nRetCode = InitSMGPAPI(NULL);
if(nRetCode)
{
printf( "InitSMGPAPI Return Error\n ");
}
/* Call SMGPDeliver To Get Message */
nRetCode = SMGPDeliver((int)RECV_MSG_TIME_OUT,&g_DeliverResp);
if(nRetCode)
{
printf( "Recv Msg From SMGW Fail!\n ");
}
else
{
printf( "Recv Msg From SMGW Success!\n ");
}
return 0;
}
涉及到的头文件及 DLL文件都在同一目录下。
smgpapi.h 如下:
#ifndef _SMGP_API_H_
#define _SMGP_API_H_
/*#define SMGP_CLIENT_VERSION10*/
#ifdef SMGP_API_EXPORTS
#define SMGPAPI_EXPORTS int __stdcall
#else
#define SMGPAPI_EXPORTS int
#endif
#ifdef _WIN32
#pragma pack(push,1)
#elif defined _AIX
#pragma options align=packed
#elif defined _HPUX
#pragma pack 1
#else
#pragma pack (1)
#endif
/* Send Batch Message Responce Which Is Written In File */
typedef struct
{
charsMsgID[10+1];
intnErrorCode;
charsPhoneNo[21+1];
}SendBatchResp;
/* Query Message Responce Struct */
typedef struct
{
intnMT_TLMsg;
intnMT_TLusr;
intnMT_Scs;
intnMT_WT;
intnMT_FL;
intnMO_Scs;
intnMO_WT;
intnMO_FL;
}QueryResp;
/* Receive Message Responce Struct */
#ifdef SMGP_API_EXPORTS
/*DLL VERSION*/
typedef struct
{
unsigned intnIsReport;
unsigned intnMsgFormat;
unsigned intnMsgLength;
charsMsgID[10+1];
charsRecvTime[14+1];
charsSrcTermID[21+1];
charsDestTermID[21+1];
charsMsgContent[252+1];
char sReserve[8+1];
}DeliverResp;
typedef struct
{
unsigned int nSerialNo; /*消息头中的流水号*/
unsigned int nStatus;
unsigned int nMsgType;
unsigned int nMsgFormat;
unsigned int nDesMode;
unsigned int nKeySerialNo;
unsigned int nIIType;
unsigned int nMsgLength;
charsMsgID[20+1];
charsSrcTermID[21+1];
charsDestTermID[21+1];
charsSessionID[20+1];
charsServiceID[10+1];
charsCpID[8+1];
char sTermID[9+1];
char sICCardID[15+1];
charsMsgContent[254+1];
}TransactionRecv;
#else
/*NOT DLL VERSION*/
typedef struct
{
charsMsgID[10+1];
unsigned intnIsReport;
unsigned intnMsgFormat;
charsRecvTime[14+1];
charsSrcTermID[21+1];
charsDestTermID[21+1];
unsigned intnMsgLength;
charsMsgContent[252+1];
char sReserve[8+1];
}DeliverResp;
typedef struct
{
unsigned int nSerialNo; /*消息头中的流水号*/
unsigned int nStatus;
charsMsgID[20+1];
unsigned int nMsgType;
unsigned int nMsgFormat;
charsSrcTermID[21+1];
charsDestTermID[21+1];
charsSessionID[20+1];
charsServiceID[10+1];
charsCpID[8+1];
unsigned int nDesMode;
char sTermID[9+1];
char sICCardID[15+1];
unsigned int nKeySerialNo;
unsigned int nIIType;
unsigned int nMsgLength;
charsMsgContent[254+1];
}TransactionRecv;
#endif /*SMGP_API_EXPORTS*/
#ifdef _WIN32
#pragma pack(pop)
#elif defined _AIX
#pragma options align=reset
#elif defined _HPUX
#pragma pack 4
#else
#pragma pack ()
#endif
#ifdef __cplusplus
extern "C "{
#endif
SMGPAPI_EXPORTS InitSMGPAPI(const char *sINIFile);
SMGPAPI_EXPORTS SMGPDeliver(const int nTimeoutIn, DeliverResp *pDeliverResp);
/...... 此处我省略了一些 函数声明 ........./
#ifdef __cplusplus
}
#endif
#endif /* _SMGP_API_H_ */
编译器 C-Free 3.5 XP 系统
可以成功编译生成 recmsg.o 文件,但构建工程时提示:
undefined reference to 'InitSMGPAPI '
undefined reference to 'SMGPDeliver '
[解决办法]
显然是没有加载DLL...