2017-06-26 156 views
1

我有一個程序,它與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 
+0

請在每個源上方提供程序名稱,以便錯誤有意義。 – JoshMc

+0

我添加了程序名 – SamOl

回答

0

正如我在答覆中已經說過你的以前的問題 「My C with MQ receive a message return code 2037」:顯示的MQCONNX使用

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.

一個樣品是amqscnxc.c

基於錯誤: /home/avalanche/oleg/src/dte_dbus_mq.c:36:錯誤: 'ClientConn' 未申報(在一次使用此功能)

需要聲明/初始化ClientConn爲例如:

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

MQCD  ClientConn = {MQCD_CLIENT_CONN_DEFAULT}; 
+0

即使我做了它,反正錯誤是一樣的。我知道這些功能,並使用它們。但是我工作的這個計劃已經超過10年了,我們沒有資源來改變它們。我們需要照原樣使用它們,只需稍作更改 – SamOl

+0

即可立即檢查代碼。我只是忘了放它 – SamOl

+0

請讓我現在爲什麼我有這些錯誤/home/avalanche/oleg/src/dte_dbus_mq.c:25:錯誤:預計'=',',',';','asm'或'ClientConn'前的'__attribute__' /home/avalanche/oleg/src/dte_dbus_mq.c:函數'dteMqInit': /home/avalanche/oleg/src/dte_dbus_mq.c:36:error:'ClientConn'undeclared(首次在此函數中使用) /home/avalanche/oleg/src/dte_dbus_mq.c:36:錯誤:(每個未聲明的標識符僅報告一次 /home/avalanche/oleg/src/dte_dbus_mq.c:36:錯誤:對於它出現的每個函數。) – SamOl

相關問題