gpt4 book ai didi

c - dte_dbus_mq.c :40: error: expected ‘=’ , ‘,’、 ‘;’、 ‘asm’ 或 ‘__attribute__’ 之前的 ‘ClientConn’

转载 作者:太空宇宙 更新时间:2023-11-04 04:22:47 24 4
gpt4 key购买 nike

我有一个程序,它与 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] = '\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

最佳答案

正如我在回答您之前的问题“My C with MQ receive a message return code 2037”时所说:

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: error: ‘ClientConn’ undeclared (first use in this function)

例如,您需要声明/初始化 ClientConn:

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

MQCD ClientConn = {MQCD_CLIENT_CONN_DEFAULT};

关于c - dte_dbus_mq.c :40: error: expected ‘=’ , ‘,’、 ‘;’、 ‘asm’ 或 ‘__attribute__’ 之前的 ‘ClientConn’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44766328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com