【发布时间】:2018-07-04 21:37:22
【问题描述】:
问题
我正在尝试编写一个程序来监听使用JACK audio server 创建的音频流。该软件包在单独使用时可以正常工作,但是当我尝试在文件中使用它以及对标准 c++ 库(如 iostream)的引用时,在 3rd 方库和 stdint.h 之间会引发 typedef 冲突错误。
对于文件,我使用了来自 JACK 包的 jack/jack.h 和 jack/types.h。它们包括对 systemdeps.h 文件(在下面展开)的引用,这是错误的根源。
我试图在网上找到解决方案,但似乎没有任何效果。任何对可能导致此问题的原因的见解,或解决问题的正确方向,我们将不胜感激。
错误信息
2>\Jack\includes\jack/systemdeps.h(69): error C2371: 'int8_t': redefinition; different basic types (compiling source file src\jack\jack_interface.cpp)
2>stdint.h(17): note: see declaration of 'int8_t' (compiling source file src\jack\jack_interface.cpp)
2>\Jack\includes\jack/systemdeps.h(73): error C2371: 'int32_t': redefinition; different basic types (compiling source file src\jack\jack_interface.cpp)
2>stdint.h(19): note: see declaration of 'int32_t' (compiling source file src\jack\jack_interface.cpp)
2>\Jack\includes\jack/systemdeps.h(74): error C2371: 'uint32_t': redefinition; different basic types (compiling source file src\jack\jack_interface.cpp)
2>stdint.h(23): note: see declaration of 'uint32_t' (compiling source file src\jack\jack_interface.cpp)
我的实现
// jack_interface.cpp
#include <iostream>
#include "jack/jack.h" // Core library .h
#include "jack/types.h" // library types .h
#include "jack/jack_interface.h" // My .h extending the lib
namespace jack
{
}
这是我可以写的导致错误被抛出的最低限度。
jack_interface.h 为空。
jack.h 和 types.h 都包含对 systemdeps.h 的引用,其中正在创建冲突。
仅在同时包含库和引用 stdint.h 的任何标准 C++ 文件时抛出错误,例如iostream。如果我删除 iostream,库功能 100%。
我从 3rd 方包中使用的库适用于 32 位 Windows。我正在使用 Visual Studio 2017 编译 32 位。
systemdeps.h
引发冲突的库头文件。抛出错误的行已在下面标记。 See file on github here.
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(GNU_WIN32)
#include <windows.h>
#ifdef _MSC_VER /* Microsoft compiler */
#define __inline__ inline
#if (!defined(int8_t) && !defined(_STDINT_H))
#define __int8_t_defined
typedef char int8_t; <-- ERROR
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef long int32_t; <-- ERROR
typedef unsigned long uint32_t; <-- ERROR
typedef LONGLONG int64_t;
typedef ULONGLONG uint64_t;
#endif
【问题讨论】:
-
您应该向库开发人员提交错误报告。
-
你唯一能做的就是在你的代码中为这个库实现一个门面,它只包含它们的头文件,你的头文件和你的门面的接口,然后编写你的主要 C++ 代码来使用门面.
-
您可以尝试将
_STDINT_H定义为一种解决方法。或者也许它应该通过某种配置头来定义。systemdeps.h文件一团糟…… -
只是猜测,但如果您在任何这些 Jack 标头之前添加
#include <stdint.h>,问题可能会得到解决。这样您就可以从<stdint.h>以及包含保护中获得这些类型的定义(假设包含保护的名称是_STDINT_H是正确的)。 -
克里斯和@PeteBecker:值得将皮特的评论推广到答案。它对使用 Jack 的人非常有用。
标签: c++