extern "C" with variable name "virtual"
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!
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 */
};
Here's a possible solution:
Add #define virtual blah_blah_blah
before the include
Add #undef virtual
after the include
Edit
Now if you need to use the member virtual
you will have to call it blah_blah_blah
.
上一篇: 模拟器卡在android启动徽标上
下一篇: 外部“C”变量名称为“虚拟”