09-08-2023 01:22 PM
Im getting the following error when I compile some sample code I got from a 3rd party BlueTooth IC supplier.
"cmd_def.h"(906,1) error: redefinition of 'PACKED' with a different type: 'struct ble_msg_system_address_get_rsp_t' vs 'struct ble_msg_system_reset_cmd_t'
A header file comment suggests doing the following. Im not sure where they want the user to put the compiler directive for CVI?
/*
*
* Support for compilers other than GCC and MSVC:
*
* To support specific compiler add compiler's structure packing directives to following macro:
* PACKSTRUCT( decl )
*
* BGLIB uses PACKSTRUCT macro to add packing information for structures:
* PACKSTRUCT(struct wifi_msg_dfu_reset_cmd_t
* {
* uint8 dfu;
* });
*/
Thanks, Ross
Solved! Go to Solution.
09-10-2023 03:51 AM - edited 09-10-2023 04:20 AM
The PACKSTRUCT definition uses the MSVC compiler internal directive __pragma as a possibility to include packing instructions in a macro. For GCC it uses __attribute.
All directives starting with two underscores are by definition compiler specific. Other compilers may or may not support it if they feel like it. LabWindows/CVI tried in the past to be MSVC compatible but it was not only a rats race that they never could win, but MSVC also always had its very own ideas what to support and what not and in what ways.
With the replacement of the compiler backend from their own proprietary C compiler to the LLVM compiler backend, any ambitions to follow MSVC closely were more or less given up.
Unfortunately the C pre-compiler does not support to include C pre-compiler statements in C pre-compiler statements, so you can't replace the compiler internal __pragma with a pre-compiler #pragma in the according #define
That all said I just did a quick test and at least LabWindows/CVI 2020 seems to support the __pragma(pack(push,1)) syntax. Are you using an older version?
If you can't upgrade to 2020 you have two options really:
1) add a definition before including the BlueGiga header that defines the PACKSTRUCT() definition as an empty define.
#define PACKSTRUCT(decl) decl
#include "cmd_def.h"
Advantage: quick fix and all will compile fine.
Disadvantage the compiler uses default alignment. For structures saved to the internal memory of the device this will waste memory, which according to the BlueGiga documentation is precious. For structures passed to any BlueGiga library contained in a BlueGiga provided DLL, bad things will be looming for you!
2) Technically correct solution:
Edit your cmd_def.h file to add support for your older LabWindows/CVI version. Unfortunately you can't just redefine the PACKSTRUCT() macro as that requires use of C pre-compiler statements in pre-compiler statements, which no C pre-compiler that I know of would support.
But the "cmd_def.h" header file is luckily very nicely structured so that the modifications are very limited.
............
#include "apitypes.h"
#ifdef __cplusplus
extern "C"
#endif
/* Compability */
#ifndef PACKSTRUCT
/*Default packed configuration*/
#ifdef __GNUC__
#ifdef _WIN32
#define PACKSTRUCT( decl ) decl __attribute__((__packed__,gcc_struct))
#else
#define PACKSTRUCT( decl ) decl __attribute__((__packed__))
#endif
#define ALIGNED __attribute__((aligned(0x4)))
#elif __IAR_SYSTEMS_ICC__
#define PACKSTRUCT( decl ) __packed decl
#define ALIGNED
#elif _CVI_
//Redefine PACKSTRUCT and ALIGNED as empty statements for LabWindows/CVI
#define PACKSTRUCT( decl ) decl
#define ALIGNED
#elif _MSC_VER //msvc
#define PACKSTRUCT( decl ) __pragma( pack(push, 1) ) decl __pragma( pack(pop) )
#define ALIGNED
#else
#define PACKSTRUCT(a) a PACKED
#endif
#endif
............
............
#ifdef _CVI_
// pack all structures to 1 byte from now on until the pack(pop) statement
#pragma pack(push, 1)
#endif
PACKSTRUCT(struct ble_msg_system_reset_cmd_t
{
uint8 boot_in_dfu;
});
........
// lots and lots more PACKSTRUCT() definitions
........
// last PACKSTRUCT() definition
PACKSTRUCT(
struct ble_cmd_packet
{
struct ble_header header;
union{
uint8 handle;
..........
..........
};
}ALIGNED);
#ifdef _CVI_
#pragma pack(pop)
#endif
............
09-12-2023 07:32 AM
I was using CVI 2017. Made the upgrade to CVI 2020 and all is good
Thanks you, Ross