condition variables c++ windows - c++

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)

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.

Related

A simple c++ HelloWorld with cuda

I'm trying to make my first program with cuda.
So I make this simple HelloWorld with guide of various pages.
#include <cstdlib>
#include <cstdio>
#include <cuda.h>
using namespace std;
__global__ void mykernel(void) {
}
int main(void) {
mykernel<<<1,1>>>();
printf("CPU Hello World!\n");
return 0;
}
But I am getting this output:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/hellowordcuda
make[2]: Entering directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/hellowordcuda.o.d"
g++ -c -g -I/usr/local/cuda-7.5/include -MMD -MP -MF "build/Debug/GNU-Linux-x86/hellowordcuda.o.d" -o build/Debug/GNU-Linux-x86/hellowordcuda.o hellowordcuda.cpp
hellowordcuda.cpp:19:1: error: ‘__global__’ does not name a type
__global__ void mykernel(void) {
^
hellowordcuda.cpp: In function ‘int main()’:
hellowordcuda.cpp:24:1: error: ‘mykernel’ was not declared in this scope
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:11: error: expected primary-expression before ‘<’ token
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:17: error: expected primary-expression before ‘>’ token
mykernel<<<1,1>>>();
^
hellowordcuda.cpp:24:19: error: expected primary-expression before ‘)’ token
mykernel<<<1,1>>>();
^
make[2]: *** [build/Debug/GNU-Linux-x86/hellowordcuda.o] Error 1
make[2]: Leaving directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/sebastian/Dropbox/Universidad/Trabajo_de_Grado_pregrado/Codigos/HelloWordCuda'
make: *** [.build-impl] Error 2
I'm sorry for making a question so simple but I just don't find any answer for this.
Thanks a lot, any help would be greatly appreciated!
There are two things you need to do to make this work:
use the CUDA compiler driver nvcc to steer compilation of the code
rename hellowordcuda.cpp to hellowordcuda.cu when passing the code to nvcc
The second point is necessary because nvcc uses the file extension to steer compilation, and if you code has a .cc or .cpp file extension, it will just pass the code to the host compiler and the same compilation errors will result
In guide also below lines are mentioned,
$ nvcc hello.cu
$ a.out
Hello World!
Please change g++ to nvcc in your Makefile.
It appears you're building directly with g++. You need to use NVidia's compiler (nvcc) to use CUDA, and make sure it knows to process the file as CUDA C. This can be achieved by changing the extension to .cu, or by playing around with compilation options which specify the file & processing type. I recommend the former.

MySQL Connect/C++ 64 bit build error

I am using Netbeans and MacoSX and installed 64bit connector. On building I am getting following errors:
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/inventory
mkdir -p build/Debug/GNU-MacOSX
rm -f build/Debug/GNU-MacOSX/addproduct.o.d
g++ -c -g -Iinclude -Iinclude -MMD -MP -MF build/Debug/GNU-MacOSX/addproduct.o.d -o build/Debug/GNU-MacOSX/addproduct.o addproduct.cpp
from addproduct.cpp:10:
In file included from include/mysql_connection.h:30,
include/cppconn/connection.h:31:29: warning: boost/variant.hpp: No such file or directory
In file included from addproduct.cpp:10:
include/mysql_connection.h:31:32: warning: boost/shared_ptr.hpp: No such file or directory
from addproduct.cpp:10:
In file included from include/mysql_connection.h:30,
include/cppconn/connection.h:41: error: 'boost' has not been declared
include/cppconn/connection.h:41: error: expected initializer before '<' token
include/cppconn/connection.h:43: error: 'ConnectPropertyVal' was not declared in this scope
include/cppconn/connection.h:43: error: template argument 2 is invalid
include/cppconn/connection.h:43: error: template argument 4 is invalid
include/cppconn/connection.h:43: error: invalid type in declaration before ';' token
In file included from addproduct.cpp:10:
include/mysql_connection.h:75: error: 'ConnectPropertyVal' is not a member of 'sql'
include/mysql_connection.h:75: error: 'ConnectPropertyVal' is not a member of 'sql'
include/mysql_connection.h:75: error: template argument 2 is invalid
include/mysql_connection.h:75: error: template argument 4 is invalid
include/mysql_connection.h:157: error: 'ConnectPropertyVal' is not a member of 'sql'
include/mysql_connection.h:157: error: 'ConnectPropertyVal' is not a member of 'sql'
include/mysql_connection.h:157: error: template argument 2 is invalid
include/mysql_connection.h:157: error: template argument 4 is invalid
include/mysql_connection.h:160: error: 'boost' has not been declared
include/mysql_connection.h:160: error: ISO C++ forbids declaration of 'shared_ptr' with no type
include/mysql_connection.h:160: error: expected ';' before '<' token
make[2]: *** [build/Debug/GNU-MacOSX/addproduct.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 538ms)
In Netbeans I am linking libmysqlcppconn.dylib only.
What files am I missing?
Why is it asking for BOOST? and which Boost Libs do I need to install?
mysql_connection.h includes #include <boost/shared_ptr.hpp>, you could either use latest versions of boost or modify below lines mysql_connection.h to use std::shared_ptr instead:
update
#include <boost/shared_ptr.hpp>
boost::shared_ptr< NativeAPI::NativeConnectionWrapper > proxy;
to
#include <memory>
std::shared_ptr< NativeAPI::NativeConnectionWrapper > proxy;
Have you read the documentation entitled "21.4.2. Installing MySQL Connector/C++ from Source"? Read the entire page carefully, then look for links specific to MacOSX...

Error while building FastCGI in a server running ubuntu

I want to interface FCGI with my C++ code in a server that runs ubuntu. I didn't find ubuntu under the list of tested platforms in the FCGI website, but I tried building it anyway.
./configure seems to work okay. But, when I run make, I get 2 errors, as pasted below:
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70: error: 'EOF' was not declared in this scope
fcgio.cpp:75: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86: error: 'EOF' was not declared in this scope
fcgio.cpp:87: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:113: error: 'EOF' was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory '/home/giridhar/fcgi-2.4.1-SNAP-0910052249/libfcgi'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/giridhar/fcgi-2.4.1-SNAP-0910052249'
make: *** [all] Error 2
Help in fixing this issue would be greatly appreciated.
I noticed that EOF is a C macro and it requires stdio.h which wasn't included in the fcgio.cpp file.
Adding a #include <stdio.h> to the fcgio.cpp file solves the problem, and now FCGI builds fine on Ubuntu.

fcgio.cpp:50: error: 'EOF' was not declared in this scope

I am attempting to build fastcgi on a Linux Ubuntu 10.x machine.
I run the following commands:
./configure
make
and I get the following error:
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70: error: 'EOF' was not declared in this scope
fcgio.cpp:75: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86: error: 'EOF' was not declared in this scope
fcgio.cpp:87: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:107: error: 'EOF' was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory `/somepath/fcgi-2.4.0/libfcgi'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/somepath/fcgi-2.4.0'
make: *** [all] Error 2
I notice that others have had the same problem and have asked this question in various fora etc - however, I have not as yet, seen an answer to this question/problem.
Has anyone ever managed to build fastcgi on Linux?
How do I fix this problem?
EOF is a C macro and seems that you do not have it defined in fcgio.cpp or that something has undefined it. I would first try to add #include <stdio.h> to start of fcgio.cpp.
I had the same problem on Ubuntu 11.10 Linux 64bit. Following most of #paercebal's advice I created the following patch which resolved the problem:
--- include/fcgio.h 2012-01-23 15:23:51.136063795 +0000
+++ include/fcgio.h 2012-01-23 15:22:19.057221383 +0000
## -31,6 +31,7 ##
#define FCGIO_H
#include <iostream>
+#include <stdio.h>
#include "fcgiapp.h"

Problems compiliing c++ code using cygwin

I am trying to compile some source code in cygwin (in windows 7)
and get the following error when I run the make file
g++ -DHAVE_CONFIG_H -I. -I.. -I.. -Wall -Wextra -Werror -g -O2 -MT libcommon_a Fcntl.o -MD -MP -MF .deps/libcommon_a-Fcntl.Tpo -c -o libcommon_a-Fcntl.o `test -f 'Fcntl.cpp' || echo './'`Fcntl.cpp
Fcntl.cpp: In function int setCloexec(int):
Fcntl.cpp:8: error: 'F_GETFD' was not declared in this scope
Fcntl.cpp:8: error: 'fcntl' was not declared in this scope
Fcntl.cpp:11: error: 'FD_CLOEXEC' was not declared in this scope
Fcntl.cpp:12: error: 'F_SETFD' was not declared in this scope
make[4]: *** [libcommon_a-Fcntl.o] Error 1
make[4]: Leaving directory `/abyss-1.1.2/Common'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/abyss-1.1.2'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/abyss-1.1.2'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/cygdrive/c/Users/Martin/Documents/NetBeansProjects/abyss-1.1.2_1'
make: *** [.build-impl] Error 2
The problem file is:-
#include "Fcntl.h"
#include <fcntl.h>
/* Set the FD_CLOEXEC flag of the specified file descriptor. */
int setCloexec(int fd)
{
int flags = fcntl(fd, F_GETFD, 0);
if (flags == -1)
return -1;
flags |= FD_CLOEXEC;
return fcntl(fd, F_SETFD, flags);
}
I don't understand what is going on,
the file fcntl.h is available and the varaiables that it says were not declared in this scope
do not give an error when I compile the file on its own
Any help would be much appreciated
Many Thanks
I've not built things with Cygwin, so this might be off-base, but considering that you're building on Windows, which has a case-insensitive filesystem, are you sure that the compiler can tell the difference between your header Fcntl.h and the system header fcntl.h? It might just be including your header twice and never getting the system header.
What's up with those #include statements? It seems like you have a header file in your project called Fcntl.h, is that right? Does it have include guards in it? If it does, maybe you're accidentally using the same guard as the built-in header, and as a result not getting its contents. Cygwin normally runs on a case-insensitive filesystem, so even giving those headers similar names like that is probably dangerous.