Discussion:
Compiler can't find rand_s function
(too old to reply)
Dave Burns
2006-07-12 15:24:46 UTC
Permalink
Hi, I want to use the rand_s function in my application.

I have included the following at the top of my module that uses the
function:

#define _CRT_RAND_S
#include <cstdlib>

I invoke the function as follows:
unsigned number;
errno_t err = rand_s(&number);

The compiler generates the error "C3861: 'rand_s': identifier not found". I
am using VS-2005.

I looked in cstdlib and stdlib.h. I can see the declaration in stdlib.h as
follows:
#if defined(_CRT_RAND_S)

_CRTIMP errno_t __cdecl rand_s ( __out unsigned int *_RandomValue);

#endif

There are a lot of "#if" statements in this header and I'm wondering if one
of them is negating the declaration.

Thanks for any advice, Dave
Dave Burns
2006-07-12 15:35:40 UTC
Permalink
I also tried adding the declaration to my module. It compiles now, but the
linker fails with the following:

error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl
rand_s(unsigned int *)" (__imp_?rand_s@@***@Z) referenced in function ...
Dave
Igor Tandetnik
2006-07-12 16:28:53 UTC
Permalink
Post by Dave Burns
Hi, I want to use the rand_s function in my application.
I have included the following at the top of my module that uses the
#define _CRT_RAND_S
#include <cstdlib>
unsigned number;
errno_t err = rand_s(&number);
Try std::rand_s. Note that you are including <cstdlib> rather than
<stdlib.h> - presumably so that CRT functions be in std namespace.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Continue reading on narkive:
Loading...