Build errors when including <net/system_client.h>

Hi,

I’m trying to get my device connected to the golioth network and am working through a few examples. The issue I am having however is that I can’t compile when I include the Giolioth Zephyr SDK in my project.

Doing this:

#include <net/golioth/system_client.h>

Gives me the following failure:

/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/lightdb.h:22:6: error: use of enum 'golioth_content_format' without previous declaration
   22 | enum golioth_content_format;
      |      ^~~~~~~~~~~~~~~~~~~~~~
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/lightdb.h:42:33: error: use of enum 'golioth_content_format' without previous declaration
   42 |                            enum golioth_content_format format,
      |                                 ^~~~~~~~~~~~~~~~~~~~~~
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/lightdb.h:60:30: error: use of enum 'golioth_content_format' without previous declaration
   60 |                         enum golioth_content_format format,
      |                              ^~~~~~~~~~~~~~~~~~~~~~
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/lightdb.h:83:33: error: use of enum 'golioth_content_format' without previous declaration
   83 |                            enum golioth_content_format format,
      |                                 ^~~~~~~~~~~~~~~~~~~~~~
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/lightdb.h:102:30: error: use of enum 'golioth_content_format' without previous declaration
  102 |                         enum golioth_content_format format,
      |                              ^~~~~~~~~~~~~~~~~~~~~~
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/lightdb.h:123:37: error: use of enum 'golioth_content_format' without previous declaration
  123 |                                enum golioth_content_format format,
      |                                     ^~~~~~~~~~~~~~~~~~~~~~
In file included from /home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth.h:13:
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/stream.h:41:33: error: use of enum 'golioth_content_format' without previous declaration
   41 |                            enum golioth_content_format format,
      |                                 ^~~~~~~~~~~~~~~~~~~~~~
/home/cmabon/ncs/v2.5.0-rc1/modules/golioth/include/net/golioth/stream.h:60:30: error: use of enum 'golioth_content_format' without previous declaration
   60 |                         enum golioth_content_format format,

``The project is using the NRF Connect SDK, version 2.5 withe version 0.8 of the Golioth library. The project is being built with C++ but including it through a C file wrapped in Extern “C” didn’t cause any change.

Any help would be greatly appreciated.

Hey Camry,

Looks like your compiler can’t find Golioth header files. Can your try the following?

  • build the Golioth hello sample, found at modules/lib/golioth/samples/hello ?
  • make a C project and include the net/golioth/system_client.h header file?
  • change #include <net/golioth/system_client.h> to #include "net/golioth/system_client.h" ?

Hi,

Thanks for the quick response. Please see the below.

1 → Building the helo sample went perfect. Used the NRF9160dk build target without issue.
2 → Empty C project also built correctly.
3 → Same issue as before

Hmm, issue here seems to be that I’m working with C++ in Zephyr. Given that it would take a large amount of work to rewrite chunks of the code in C is there any workaround that you guys are aware of here?

From the initial comment, I assume you did the following:

#ifdef __cplusplus 
extern "C" {
#endif

// golioth header file content

#ifdef __cplusplus 
}
#endif

in all Golioth header files?

Added the extern to all of the Golioth headers and am still getting the same issue when going to build the project.

It would seem that in this case, the problem lies in the forward declaration of enums, which you can do in C but not in C++.

Here’s one workaround, by conditionally specifying the size of the enum when using C++ in lightdb.h and stream.h:

struct golioth_client;

enum golioth_content_format
#ifdef __cplusplus
: uint32_t
#endif
;

Hi again,

After trying to get it working in C++ I made the call that I was fighting an uphill battle and just took the time to rewrite everything in C.

Really like the product but would really love to see C++ support in the zephyr sdk given zephyrs support for C++!