从标头生成gSOAP文件时无法识别定义

时间:2019-04-10 12:22:49

标签: c++ gsoap

我正在尝试从头文件生成gsoap类

soapcpp2.exe test.h

其中test.h

// test.h

#define MY_STRUCT_NAME_LEN 50

typedef struct MY_STRUCT_TYPE
{
    char name[MY_STRUCT_NAME_LEN];
}MY_STRUCT;

int op1(MY_STRUCT* a, int b, int * r );

我的问题是#define MY_STRUCT_NAME_LEN 50等号线:3无法识别。

test.h(7): *WARNING*: undefined identifier 'MY_STRUCT_NAME_LEN'


test.h(7): *WARNING*: char[30681240620171331] will be serialized as an array of 30681240620171331 bytes: use soapcpp2 option -b to enable char[] string serialization or use char* for strings


    test.h(7): **ERROR**: undetermined array size

    Saving soapStub.h annotated copy of the source interface header file
    Saving soapH.h serialization functions to #include in projects

    test.h(12): *WARNING*: serializable typedef 'MY_STRUCT' is not namespace qualified: schema definition for 'MY_STRUCT' in WSDL file output may be invalid

    Saving soap.nsmap namespace mapping table
    Saving soapClient.cpp client call stub functions
    Saving soapClientLib.cpp client stubs with serializers (use only for libs)
    Saving soapServer.cpp server request dispatcher
    Saving soapServerLib.cpp server request dispatcher with serializers (use only for libs)
    Saving soapC.cpp serialization functions

    There were errors:
    1 semantic error
    3 warnings

如果我将第7行更改为

char name[50];

它将正常工作。

我真的更喜欢使用宏来表示字符串的大小(实际情况更复杂)。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

此问题被标记为C ++,并且您正在使用soap cpp 2:您可能不应该对字符串使用define,typedef struct ...和char数组。这就是说,如果没有特别的原因来限制字符串长度,则将代码重写为:

class test {
    public:
    std::string name;
};

int op1(test* a, int b, int * r );

编译成功,没有任何警告。