rand_r not in scope, gcc mingw under cygwin on windows
c++, cygwin, gcc, windows
Solution
The `rand_r` function is considered thread safe, compared to the standard `rand` function. See man 3 rand_r.
One option is to implement `rand_r` yourself by wrapping a call to `rand`. This may or may not be desirable, and as the manual states, `rand_r` is a fairly weak pseudo-random number generator anyway.
Seeing as you're using C++, why not take a look at the new random number libraries available. They are thread safe, portable, and produce much better random results. This question, while closed as not a real question, still contains some useful information on how to use the library.
If you don't have the C++11 random classes available, Boost also has an implementation.
Problem
I am trying to port some code from linux to windows under cygwin. I find this weird error where 'rand_r is not declared in this scope'. I am using gcc 4.8.1 as x86_64-w64-mingw32 and in it's search path (-v option) it does look in the right directories. The header files are included properly. I am looking for ideas to solve this problem. Is there some fact about cygwin that I am missing and therefore having this problem? Is there a way to check if gcc is in fact touching the required files?