Reputation: 153
I am trying to run some code copied from Windows Dev Center, but keep encountering an error over some unresolved identifiers. This maybe sound silly, but why would these lines cause this error:
CONDITION_VARIABLE BufferNotEmpty;
CONDITION_VARIABLE BufferNotFull;
And "not declared in this scope" on other lines similar to this:
SleepConditionVariableCS (&BufferNotFull, &BufferLock, INFINITE);
When I've included all the headers (or at least i think) necessary?
#include <mutex>
#include <condition_variable>
#include <cstdint>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <WinBase.h>
Running NetBeans with project configured to C++11 in case that changes anything. Thanks in advance if anyone has any suggestions!
EDIT:
Error output:
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)
Upvotes: 0
Views: 1326
Reputation: 18360
What happens if you add
#include <SDKDDKVer.h>
Before the #include <windows.h>
?
The CONDITION_VARIABLE
definition should be brought in by <windows.h>
, but only if building against Vista-or-newer. <sdkddkver.h>
should ensure you're always building against the newest target supported by the SDK.
If that doesn't help, or if <sdkddkver.h>
isn't found, then it means that your build environment is using a very old, very stale SDK. I don't know what NetBeans/mingw uses for its Windows SDK, so it's quite plausible that they use a stale version.
If this proves to be the case then I think your best option would be to use Visual Studio 2015 or 2017 Community Edition along with the current Windows 10 SDK.
Upvotes: 1