Han*_*ans 5 c++ qt include header-files
我正在使用Ubuntu 14.04上的Qt Creator创建一个GUI来控制硬件.我有一个类来控制一个摄像头(camera.h)和一个类来控制连接到USB RS232串行转换器(light.h)的光源.此类的两个头文件包括制造商提供的标题:uEye.h以及ftdi2xx.h相机和串行转换器.如果我单独使用它们,两个库都可以正常工作 但是当我尝试将它们包含在我的内容中时,mainwindow.h我会收到以下错误消息(大约14个):
/home/g/Desktop/release/WinTypes.h:14: error: conflicting declaration
'typedef unsigned int BOOL'
typedef unsigned int BOOL;
/usr/include/uEye.h:1570: error: 'BOOL' has a previous declaration as
'typedef int32_t BOOL'
typedef int32_t BOOL;
Run Code Online (Sandbox Code Playgroud)
等等.我从其他帖子中了解到,在C++中似乎没有简单的解决方法.有任何建议如何解决(除了使用不同的硬件或有两个单独的程序)?
更新:
最后我找到了一个解决方法,虽然它仍然不是我的问题的确切答案.我做了以下:我去了ftdi2xx.h文件并评论了导致的麻烦#include WinTypes.h.在light.h我uEye.h首先包括(我猜这个标题包括某种WinTypes.h).然后我需要添加一些在包含之前typedef没有隐藏的遗漏声明.它有效,但它不是一个非常干净和漂亮的解决方案,因为它涉及搞乱第三方的东西. uEye.hftdi2xx.h
一种解决方案是调整 BOOL 的库定义,如下所示
#ifndef BOOL //if BOOL not defined yet
#define BOOL
Run Code Online (Sandbox Code Playgroud)
另一种方法是在您的代码中,在包含这两个文件之后,您可以定义自己的 BOOL,这不会给它们带来任何问题。
#include "uEye.h"
#undef BOOL
#include "ftdi2xx.h"
Run Code Online (Sandbox Code Playgroud)
或者也
#include "uEye.h"
#undef BOOL
#include "ftdi2xx.h"
#undef BOOL
typedef unsigned int BOOL;
Run Code Online (Sandbox Code Playgroud)