I was working on a wayland compositor based on C++. My project uses wlroots which is a C Library. I have a set of header files in wlroots which i need to add to my C++ project. I used extern "C" to include c header files but it was showing errors on 'static' type.
/usr/local/include/wlr/render/wlr_renderer.h:72:27: error: expected primary-expression before ‘static’
72 | const float color[static 4], const float projection[static 9]);
| ^~~~~~
Here is the sample code for reference :
#ifndef SERVER_HPP
#define SERVER_HPP
#include <wayland-server.h>
extern "C"
{
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
};
class Server
{
public:
struct wl_display *wl_display;
struct wl_event_loop *wl_event_loop;
struct wlr_backend *backend;
struct wlr_renderer *renderer;
struct wlr_allocator *allocator;
struct wlr_compositor *compositor;
public:
bool init();
bool run();
void terminate();
};
#endif
I did some digging and find out a way to fix it. by this method:
#define static
extern "C"
{
#include <wlr/backend.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
};
#undef static
But i am not sure whether it will cause any issues in the future. This seems to be a hack method. Is there any better method to overcome this?