I'm getting the following error when attempting to build on CentOS 6.4: The only flags being passed here are -Wall and -std=c++11, using gcc 4.7.2
/usr/local/include/rapidjson/writer.h: In member function ‘void rapidjson::Writer::WriteDouble(double)’: /usr/local/include/rapidjson/writer.h:173:53: error: there are no arguments to ‘_snprintf’ that depend on a template parameter, so a declaration of ‘_snprintf’ must be available [-fpermissive] /usr/local/include/rapidjson/writer.h:173:53: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
The code in question: (from rapidjson/writer.h)
void WriteDouble(double d) {
char buffer[100];
#if _MSC_VER
int ret = sprintf_s(buffer, sizeof(buffer), "%g", d);
#else
int ret = snprintf(buffer, sizeof(buffer), "%g", d); //this line is the troublemaker
#endif
RAPIDJSON_ASSERT(ret >= 1);
for (int i = 0; i < ret; i++)
stream_.Put(buffer[i]);
}
The top of the writer.h file looks like this:
#ifndef RAPIDJSON_WRITER_H_
#define RAPIDJSON_WRITER_H_
#include "rapidjson.h"
#include "internal/stack.h"
#include "internal/strfunc.h"
#include <cstdio> // snprintf() or _sprintf_s()
#include <new> // placement ne
Which led me to this question: cstdio stdio.h namespace.
As I understand the answer to the question above, the inclusion of cstdio should declare the snprintf symbol in the standard namespace. So, I thought to include stdio.h to get the symbol defined in the global namespace. The same compilation error results, regardless if I include cstdio, stdio.h, or both files (which I shouldn't have to do)
My question is two parts: Why is gcc looking for _snprintf and not snprintf? Or am I on the wrong track and is this related to the two-part name lookup that gcc does for template parameter binding? (ala 10.8.2, http://idlebox.net/2009/apidocs/gcc-4.4.1.zip/gcc-4.4.1/gcc_10.html#SEC315)
stdio.h
for C++ code? – devnull/usr/local
? – devnullgcc
are you using? – devnull