条件变量c ++ windows

时间:2017-03-24 15:22:25

标签: c++ c++11 netbeans condition-variable

我正在尝试运行从Windows Dev Center复制的一些代码,但是在某些未解析的标识符上遇到错误。这可能听起来很愚蠢,但为什么这些行会导致这个错误:

CONDITION_VARIABLE BufferNotEmpty;
CONDITION_VARIABLE BufferNotFull;

并且“未在此范围内声明”在与此相似的其他行上:

SleepConditionVariableCS (&BufferNotFull, &BufferLock, INFINITE);

当我包含所有标题(或者至少我认为)必要时?

#include <mutex>
#include <condition_variable>
#include <cstdint>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <WinBase.h>

运行带有配置为C ++ 11的项目的NetBeans,以防更改任何内容。如果有人有任何建议,请提前致谢!

编辑:

错误输出:

cd 'C:\Users\Linda\Documents\NetBeansProjects\CppApplication_2'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Linda/Documents/NetBeansProjects/CppApplication_2'
"/C/MinGW/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_2.exe
make.exe[2]: Entering directory `/c/Users/Linda/Documents/NetBeansProjects/CppApplication_2'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/conditional_var.o.d"
g++ -std=c++11   -c -g -std=c++11 -MMD -MP -MF "build/Debug/MinGW-Windows/conditional_var.o.d" -o build/Debug/MinGW-Windows/conditional_var.o conditional_var.cpp
conditional_var.cpp:20:1: error: 'CONDITION_VARIABLE' does not name a type
 CONDITION_VARIABLE BufferNotEmpty;
 ^
conditional_var.cpp:21:1: error: 'CONDITION_VARIABLE' does not name a type
 CONDITION_VARIABLE BufferNotFull;
 ^
conditional_var.cpp: In function 'DWORD ProducerThreadProc(PVOID)':
conditional_var.cpp:43:40: error: 'BufferNotFull' was not declared in this scope
             SleepConditionVariableCS (&BufferNotFull, &BufferLock, INFINITE);
                                        ^
conditional_var.cpp:43:76: error: 'SleepConditionVariableCS' was not declared in this scope
             SleepConditionVariableCS (&BufferNotFull, &BufferLock, INFINITE);
                                                                            ^
conditional_var.cpp:64:33: error: 'BufferNotEmpty' was not declared in this scope
         WakeConditionVariable (&BufferNotEmpty);
                                 ^
conditional_var.cpp:64:47: error: 'WakeConditionVariable' was not declared in this scope
         WakeConditionVariable (&BufferNotEmpty);
                                               ^
conditional_var.cpp: In function 'DWORD ConsumerThreadProc(PVOID)':
conditional_var.cpp:82:40: error: 'BufferNotEmpty' was not declared in this scope
             SleepConditionVariableCS (&BufferNotEmpty, &BufferLock, INFINITE);
                                        ^
conditional_var.cpp:82:77: error: 'SleepConditionVariableCS' was not declared in this scope
             SleepConditionVariableCS (&BufferNotEmpty, &BufferLock, INFINITE);
                                                                             ^
conditional_var.cpp:111:33: error: 'BufferNotFull' was not declared in this scope
         WakeConditionVariable (&BufferNotFull);
                                 ^
conditional_var.cpp:111:46: error: 'WakeConditionVariable' was not declared in this scope
         WakeConditionVariable (&BufferNotFull);
                                              ^
conditional_var.cpp: In function 'int main()':
conditional_var.cpp:124:35: error: 'BufferNotEmpty' was not declared in this scope
     InitializeConditionVariable (&BufferNotEmpty);
                                   ^
conditional_var.cpp:124:49: error: 'InitializeConditionVariable' was not declared in this scope
     InitializeConditionVariable (&BufferNotEmpty);
                                                 ^
conditional_var.cpp:125:35: error: 'BufferNotFull' was not declared in this scope
     InitializeConditionVariable (&BufferNotFull);
                                   ^
conditional_var.cpp:141:45: error: 'WakeAllConditionVariable' was not declared in this scope
     WakeAllConditionVariable (&BufferNotFull);
                                             ^
make.exe[2]: *** [build/Debug/MinGW-Windows/conditional_var.o] Error 1
make.exe[2]: Leaving directory `/c/Users/Linda/Documents/NetBeansProjects/CppApplication_2'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Linda/Documents/NetBeansProjects/CppApplication_2'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 4s)

1 个答案:

答案 0 :(得分:1)

如果添加

会发生什么
#include <SDKDDKVer.h>

#include <windows.h>之前?

CONDITION_VARIABLE定义应由<windows.h>引入,但仅限于针对Vista或更新版本构建。 <sdkddkver.h>应确保您始终违反SDK支持的最新目标。

如果这没有帮助,或者找不到<sdkddkver.h>,那么这意味着您的构建环境正在使用一个非常旧的,非常陈旧的SDK。我不知道NetBeans / mingw对其Windows SDK使用了什么,因此它们使用陈旧版本是非常合理的。

如果证明是这种情况,那么我认为您最好的选择是使用Visual Studio 2015或2017 Community Edition以及当前的Windows 10 SDK。