我有一個程序,它與IBM MQ連接和斷開連接,我編譯時錯誤:dte_dbus_mq.c:40:error:expected'=',',';','asm'或'__attribute__''ClientConn'
dte_dbus_mq.c
#include <stdio.h>
#include <cmqc.h>
#include "dte_mq.h"
#include <string.h>
#include <stdlib.h>
typedef struct tagDTE_QUEUE_DESCRIPTOR
{
MQHOBJ handle;
int IsSyncpointControled;
} DTE_QUEUE_DESCRIPTOR, *PDTE_QUEUE_DESCRIPTOR;
#define MAX_NUM_OPEN_QUEUES 10
MQCNO Connect_options = {MQCNO_DEFAULT}; /* MQCONNX options*/
MQCD ClientConn = {MQCD_CLIENT_CONN_DEFAULT}; /* Client connection channel*/
int dteMqInit(const char *manager, char *hostname, char *channelName)
{
MQCHAR48 mgrName;
int I;
strncpy(ClientConn.ConnectionName,hostname,MQ_CONN_NAME_LENGTH);
strncpy(ClientConn.ChannelName,channelName,MQ_CHANNEL_NAME_LENGTH);
Connect_options.ClientConnPtr = &ClientConn;
Connect_options.Version = MQCNO_VERSION_2;
strncpy(mgrName, manager, MQ_Q_MGR_NAME_LENGTH);
MQCONNX(mgrName,&Connect_options, &sHConn, &sCompCode &sReason);
if (sCompCode != MQCC_OK) return DTE_MQR_FAILED;
sQueues = (PDTE_QUEUE_DESCRIPTOR)malloc(sizeof(DTE_QUEUE_DESCRIPTOR) * MAX_NUM_OPEN_QUEUES);
for(i = 0; i < MAX_NUM_OPEN_QUEUES; i++)
sQueues[i].handle = -1;
return DTE_MQR_OK;
}
下面是我的計劃,該計劃呼籲上述之一。
NewMQTest.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmqc.h> #include <cmqxc.h>
int main(int argc, char **argv)
{
MQLONG messlen;
char QMgrName[MQ_Q_MGR_NAME_LENGTH+1];
char QName[MQ_Q_NAME_LENGTH+1];
char channelName[MQ_CHANNEL_NAME_LENGTH+1];
char hostname[1024];
char port[4];
MQLONG buflen;
MQBYTE TempBuf[65536];
int msgsToGet;
int msgsGot;
int dteretinit;
int dteretdeinit;
if (argc != 6)
{
printf("Usage: NewMQTest QMgrName ChlName hostname port QName\n");
exit(-1);
}
strncpy(QMgrName, argv[1], MQ_Q_MGR_NAME_LENGTH);
QMgrName[MQ_Q_MGR_NAME_LENGTH] = '\0';
strncpy(channelName, argv[2], MQ_CHANNEL_NAME_LENGTH);
channelName[MQ_CHANNEL_NAME_LENGTH] = '\0';
strncpy(hostname, argv[3], 1023);
hostname[1023] = '\0';
strncpy(port,argv[4],4);
strncpy(QName, argv[5], MQ_Q_NAME_LENGTH);
QName[MQ_Q_NAME_LENGTH] = '\0';
printf("Using values:\n");
printf(" QMgrName : %s\n", QMgrName);
printf(" QName : %s\n", QName);
printf(" ChannelName: %s\n", channelName);
printf(" hostname : %s\n", hostname);
printf(" port : %s\n",port);
dteretinit = dteMqInit(QMgrName,hostname,channelName)
printf("Return cod from dteMqInit = %d\n",dteretinit);
}
下面是錯誤的,這是我收到的編譯時間。
/home/avalanche/oleg/src/dte_dbus_mq.c:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ClientConn’
/home/avalanche/oleg/src/dte_dbus_mq.c:31: error: conflicting types for ‘dteMqInit’
/home/avalanche/oleg/inc/dte_mq.h:16: error: previous declaration of ‘dteMqInit’ was here
/home/avalanche/oleg/src/dte_dbus_mq.c: In function ‘dteMqInit’:
/home/avalanche/oleg/src/dte_dbus_mq.c:36: error: ‘ClientConn’ undeclared (first use in this function)
/home/avalanche/oleg/src/dte_dbus_mq.c:36: error: (Each undeclared identifier is reported only once
/home/avalanche/oleg/src/dte_dbus_mq.c:36: error: for each function it appears in.)
make: *** [/home/avalanche/oleg/src/dte_dbus_mq.o] Error 1
請在每個源上方提供程序名稱,以便錯誤有意義。 – JoshMc
我添加了程序名 – SamOl