dte_dbus_mq.c:40: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ClientConn’

dte_dbus_mq.c:40: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ClientConn’

我有一个程序,它与 IBM MQ 连接和断开连接,它给我编译时错误:

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] = '[=11=]';     

     strncpy(channelName, argv[2], MQ_CHANNEL_NAME_LENGTH);     
     channelName[MQ_CHANNEL_NAME_LENGTH] = '[=11=]';     

     strncpy(hostname, argv[3], 1023);     
     hostname[1023] = '[=11=]';     

     strncpy(port,argv[4],4);     

     strncpy(QName, argv[5], MQ_Q_NAME_LENGTH);     
     QName[MQ_Q_NAME_LENGTH] = '[=11=]';     

     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  

正如我在回答您之前的问题“”时所说:

I would suggested that you review the sample applications provided with the IBM MQ install. On Linux these would be located in /opt/mqm/samp. The sample amqsget0.c would be similar to your program except it is using a MQCONN not MQCONNX.

显示 MQCONNX 用法的一个示例是 amqscnxc.c

基于错误: /home/avalanche/oleg/src/dte_dbus_mq.c:36: 错误:‘ClientConn’未声明(首次在此函数中使用)

您需要 declare/initialize ClientConn 例如:

#include <cmqxc.h>                 /* For MQCD definition           */

MQCD     ClientConn = {MQCD_CLIENT_CONN_DEFAULT};