Static_assert Error in generated include file

I’m using these commands to generate my include files:

$ nnvg --target-language c --target-endianness=little --enable-serialization-asserts uavcan --outdir uavcan_messages

$ nnvg --target-language c --target-endianness=little --enable-serialization-asserts reg --lookup-dir uavcan --outdir uavcan_messages

$ nnvg --target-language c --allow-unregulated-fixed-port-id --target-endianness=little --enable-serialization-asserts fortem_msgs --lookup-dir uavcan --outdir uavcan_messages

Every one of my generated include files contains these types of static_assert errors:

static_assert( NUNAVUT_SUPPORT_LANGUAGE_OPTION_OMIT_FLOAT_SERIALIZATION_SUPPORT == 0,
              "<< MY DIRECTORY >>/directives/160.LightsCommand.1.0.uavcan is trying to use a serialization library that was compiled with "
              "different language options. This is dangerous and therefore not allowed." );

Does anyone have an idea what might be going wrong? “OMIT_FLOAT_SERIALIZATION_SUPPORT” seems to be a hint, but I don’t know where to start looking.

Thank you in advance!

What does your serialization.h look like?

Specifically the one I generated looks like this (with a bit of code removed, the defines are the important bit):

// UAVCAN common serialization support routines.                                                             +-+ +-+
// This file is based on canard_dsdl.h, which is part of Libcanard.                                          | | | |
//                                                                                                           \  -  /
// AUTOGENERATED, DO NOT EDIT.                                                                                 ---
//                                                                                                              o
//---------------------------------------------------------------------------------------------------------------------
// Language Options
//     target_endianness:  little
//     omit_float_serialization_support:  False
//     enable_serialization_asserts:  True
//     enable_override_variable_array_capacity:  False

// [some boilerplate here... ignoring so the post isn't huge]

static_assert(sizeof(size_t) >= sizeof(size_t),
    "The bit-length type used by Nunavut, size_t, "
    "is smaller than this platform's size_t type. "
    "Nunavut serialization relies on size_t to size_t conversions "
    "that do not lose data. You will need to regenerate Nunavut serialization support with a larger "
    "unsigned_bit_length type specified.");

#define NUNAVUT_SUPPORT_LANGUAGE_OPTION_TARGET_ENDIANNESS 434322821
#define NUNAVUT_SUPPORT_LANGUAGE_OPTION_OMIT_FLOAT_SERIALIZATION_SUPPORT 0
#define NUNAVUT_SUPPORT_LANGUAGE_OPTION_ENABLE_SERIALIZATION_ASSERTS 1
#define NUNAVUT_SUPPORT_LANGUAGE_OPTION_ENABLE_OVERRIDE_VARIABLE_ARRAY_CAPACITY 0

// [the rest of the file]

You seem to be either not including this file (unlikely, the other asserts would be triggering as well, and you’d be getting an include error), or using the wrong version of the file. This should be in uavcan_messages/nunavut/support/serialization.h.

You can check to see if nunavut is generating serialization.h by adding the --list-outputs option to one of your commands. It should be generated every time you run nunavut, and if it isn’t, that may be your issue.

1 Like

My serialization,.h starts like this:

static_assert(sizeof(size_t) >= sizeof(size_t),
    "The bit-length type used by Nunavut, size_t, "
    "is smaller than this platform's size_t type. "
    "Nunavut serialization relies on size_t to size_t conversions "
    "that do not lose data. You will need to regenerate Nunavut serialization support with a larger "
    "unsigned_bit_length type specified.");

. . .

// API usage errors:
#define NUNAVUT_ERROR_INVALID_ARGUMENT                  2
#define NUNAVUT_ERROR_SERIALIZATION_BUFFER_TOO_SMALL    3
// Invalid representation (caused by bad input data, not API misuse):
#define NUNAVUT_ERROR_REPRESENTATION_BAD_ARRAY_LENGTH        10
#define NUNAVUT_ERROR_REPRESENTATION_BAD_UNION_TAG           11
#define NUNAVUT_ERROR_REPRESENTATION_BAD_DELIMITER_HEADER    12

. . .

// The rest of the file

I started the generation sequence by sending :
nnvg --target-language c --target-endianness=little --enable-serialization-asserts --list-outputs uavcan --outdir
uavcan_messages

The very last file listed in a HUGE list of .h’s was: uavcan_messages/nunavut/support/serialization.h

Are there any obvious issues?

I probably should have been more specific, the important feature of serialization.h would be
this define:

#define NUNAVUT_SUPPORT_LANGUAGE_OPTION_OMIT_FLOAT_SERIALIZATION_SUPPORT 0

If it defines this macro as anything other than 0, then we’ve found the problem, and need to figure out why it’s generating this file differently. If it is 0, then you probably need to double-check your include paths.

1 Like

This line is in my serialization.h:

#define NUNAVUT_SUPPORT_LANGUAGE_OPTION_OMIT_FLOAT_SERIALIZATION_SUPPORT 0

Please forgive a total noob, but where do I look for my include paths?

I apologize for the silly question but is the assert actually triggered or are you just questioning why is it present in the generated code at all? Does the code compile?

The code does not compile. Assertion errors galore.

What compiler/build system/IDE are you using? What did you change in your build settings to include the generated headers?

I’m compiling/building in an Ubuntu terminal. I have generated include files that were done by a coworker that compile and run well. He has since left the company. The instructions he left to generate the files “work”, but the generated code will not compile (assertion errors). I’m left to clean up.

Two more pieces of information I did not include. Versions:

$ python
Python 2.7.17 (default, Feb 27 2021, 15:10:58)
[GCC 7.5.0] on linux2

$ nnvg --version
1.1.0

Are these the right versions?

One more piece of information that stands out. The version of generated include files that has the “static_assert” error also has this in the header"

// Generator: nunavut-1.1.0 (serialization was enabled)

The version of generated include files that compile has this in the header:

// Generator: nunavut-0.6.4 (serialization was enabled)

Do I need to somehow downgrade versions of nunavut?

I think you can close this one out. I found the issue with an older copy of serialization,h. I updated t he file and all is well. Thank you.