Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extern "C" with variable name "virtual"

Tags:

c++

extern

qt

drm

I'm trying to create a simple C++ test application based off Qt 5.1 configure KMS functional test (qtbase/config.tests/qpa/kms), which is failing. The application is very simple as shown below:

#include <stdlib.h>
extern "C" {
#include <gbm.h>
#include <xf86drmMode.h>
#include "xf86drm.h"
}
#include <EGL/egl.h>
#include <GLES2/gl2.h>

int main(int, char **)
{
    // Check for gbm_surface which is quite a recent addition.
    gbm_surface *surface = 0;

    return 0;
}

The problem is that when including "libdrm/xf86drmMode.h" or "libdrm/xf86drm.h", "drm/drm.h" is also included. Within "drm.h" there is a structure defined as:

struct drm_buf_map {
    int count;              /**< Length of the buffer list */
    void *virtual;              /**< Mmap'd area in user-virtual */
    struct drm_buf_pub *list;   /**< Buffer information */
};

Notice the variable named "virtual" within the drm_buf_map structure. This causes a C++ compiler error, which cannot be resolved by using extern "C". This makes sense, but I'm not sure how to go about solving this problem (other than using the C compiler). Is there a compiler flag to handle this?

Thanks!

like image 517
Michael Avatar asked Sep 26 '13 17:09

Michael


1 Answers

The real issue here is that you are including a wrong drm.h. You are not using a package manager and also do not specify /usr/include/libdrm in the include path. If one of these two is not done, the compiler is going to pick up /usr/include/drm.h or another that has this issue. But the file from libdrm (/usr/include/libdrm/drm.h) has this fixed.

Refer to the real drm.h file — that already has Eric’s patch for this 4 years back:

struct drm_buf_map {
int count;  /**< Length of the buffer list */
#ifdef __cplusplus
void *virt;
#else
void *virtual;  /**< Mmap'd area in user-virtual */
#endif
struct drm_buf_pub *list;   /**< Buffer information */
};
like image 58
Prabindh Avatar answered Oct 11 '22 06:10

Prabindh