简体   繁体   English

使用 IAR 编译 Cypress 软件时出现问题

[英]Problem compiling Cypress software with IAR

I've a Cypress BLE module and have compilation problem with IAR.我有一个 Cypress BLE 模块,但 IAR 有编译问题。 In "ezsapi.h" are defined this macros:在“ezsapi.h”中定义了这个宏:

#ifdef __GNUC__
    /* standard GNU C */
    #ifdef _WIN32
        /* MinGW, Cygwin, TDM-GCC, etc. */
        #define __PACKDEF(STRUCTNAME, STRUCTDEF) typedef struct STRUCTDEF __attribute__((__packed__,gcc_struct)) STRUCTNAME
    #else
        /* generic gcc */
        #define __PACKDEF(STRUCTNAME, STRUCTDEF) typedef struct STRUCTDEF __attribute__((__packed__)) STRUCTNAME
    #endif
    #define ALIGNED __attribute__((aligned(0x4)))
#else
    /* Microsoft Visual C++ */
    #define __PACKDEF(STRUCTNAME, STRUCTDEF) __pragma(pack(push, 1)) STRUCTDEF __pragma(pack(pop)) STRUCTNAME
    #define ALIGNED
#endif

IAR usually use #pragma pack(push,1) and #pragma pack(pop) and I tryed to modify the macro in: IAR 通常使用#pragma pack(push,1)#pragma pack(pop) ,我尝试修改宏:

#define __PACKDEF(STRUCTNAME, STRUCTDEF) #pragma(pack(push, 1)) STRUCTDEF #pragma(pack(pop)) STRUCTNAME

With original macros the errors reported is:使用原始宏,报告的错误是:

ezsapi.h(694) : Error[Pe020]: identifier "pack" is undefined
ezsapi.h(694) : Error[Pe018]: expected a ")" ezsapi.h(694) :
Error[Pe079]: expected a type specifier ezsapi.h(694) : Error[Pe260]:
explicit type is missing ("int" assumed) ezsapi.h(694) : Error[Pe141]:
unnamed prototyped parameters not allowed when body is present
ezsapi.h(694) : Error[Pe130]: expected a "{"

and with my macro the errors reported is:使用我的宏,报告的错误是:

(69 is the line where the macro is located)
ezsapi.h(69) : Error[Pe052]: expected a macro parameter name
ezsapi.h(69) : Error[Pe052]: expected a macro parameter name
ezsapi.h(694) : Error[Pe020]: identifier "pack" is undefined
ezsapi.h(694) : Error[Pe018]: expected a ")" ezsapi.h(694) :
Error[Pe079]: expected a type specifier ezsapi.h(694) : Error[Pe260]:
explicit type is missing ("int" assumed) ezsapi.h(694) : Error[Pe141]:
unnamed prototyped parameters not allowed when body is present
ezsapi.h(694) : Error[Pe130]: expected a "{"

What's the correct formula for IAR? IAR 的正确公式是什么? What's escaping me? escaping 我是什么?

Thanks.谢谢。

There are two ways of solving this problem.有两种方法可以解决这个问题。 My suggestion is that you use the __packed type attibute instead of #pragma pack() as this has a more well defined meaning.我的建议是您使用__packed类型属性而不是#pragma pack()因为它具有更明确定义的含义。 This, however, needs IAR language extensions to be switched on.然而,这需要打开 IAR 语言扩展。 If you can't enable language extensions or for some other reason need to use pack-pragma you have to use an alternative pragma syntax to be able to include it in a preprocessor macro.如果您不能启用语言扩展或出于某些其他原因需要使用 pack-pragma,则必须使用替代 pragma 语法才能将其包含在预处理器宏中。 If you use _Pragma("pack(push,1)") and _Pragma("pack(pop)") you macro should work as expected.如果你使用_Pragma("pack(push,1)")_Pragma("pack(pop)")你的宏应该按预期工作。 Definitions of PACKDEF for both alternatives are shown below:两种选择的 PACKDEF 定义如下所示:

#define PACKDEF(STRUCTNAME, STRUCTDEF) typedef __packed struct STRUCTDEF STRUCTNAME

#define PACKDEF(STRUCTNAME, STRUCTDEF)  _Pragma("pack(push,1)") typedef struct STRUCTDEF STRUCTNAME _Pragma("pack(pop)")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM