Re: msvc and strdup?
On May 11, 2:02 am, Larry Smith <lsm...@nospam.com> wrote:
Michael Holm wrote:
Ever so often when I try to compile some open source code, I get a erro=
r,
pbrtparse.y(205) : error C3861: 'strdup': identifier not found
In the example, I'm trying to compile pbrt (http://www.pbrt.org/).
And I have been searching all over the net for it, and it seems I'm the
only one having a problem with strdup.
What do I do wrong?
I suspect it could be my installation that's bogus, but I'd like to hear
your opinions before formatting my C:\ :)
Any pointers are highly appreciated.
Microsoft has a _strdup function (notice the leading underscore).
They also have an strdup function, at least in VC 2005.
They used to have a "#define" that defined "strdup" as "_strdup",
but in their later compilers they have removed that define.
You could add the define yourself, or you could change the
source code to use _strdup.
Microsoft's latest compilers now issue "deprecated" warnings
for many ANSI/POSIX functions (all of the str... functions
for example). There is a define (_CRT_NONSTDC_NO_DEPRECATE)
you can add to turn off those warnings, or you can use the
"/wd4996" compiler switch.
The define does NOT turn off the warnings for Posix functions;
only those functions in ISO C which have a replacement in the
ISO C TR.
Microsoft wants folks to use their new, non-standard,
functions in place of the ANSI/POSIX functions.
They say for safety, but if you use their new functions
your code will be Windows-specific (non-portable).
Well, given that the replacement functions are in a TR defined
by the C standards committee, one would hope that they would be
supported by any up to date C compiler. (Of course, in
practice, even C99 is only supported about like C++ 98 with
export. So "up to date C compiler" is probably a contradiction
in itself.)
The function in question, strdup, has never been part of
standard C/C++, and its presence in <string.h> is forbidden by
both ISO standards. In practice, of course... all of the
compilers I have access to do include it, by default at least.
So much for standards compliance.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34