curl-library
7.18.2: Compilation with MS Visual Studio 2005 causes error C2894 / extern "C" problem
Date: Wed, 01 Oct 2008 20:20:46 +0200
Hi libCurl users,
I have got a C++ file which includes the curl.h header and which cannot
be compiled. The following error is generated
C:\Program Files\Microsoft Platform SDK for Windows Server 2003
R2\Include\wspiapi.h(44) : error C2894: templates cannot be declared to
have 'C' linkage
The file's content is:
...
extern "C"
{
#include "curl/curl.h"
}
In curl.h line 59 ws2tcpip.h is included. That file itself includes
wspiapi.h.
I assume that the error occurs because I placed #include "curl/curl.h"
in an extern "C" section and I compiled a C++ file. In that case,
the preprocessor flag __cplusplus is set by the compiler and in
wspiapi.h at line 44 the template is instantiated.
Now, the solution seems fairly simple. I just remove the extern "C"
section. In curl.h, multi.h, easy.h etc extern "C" sections are already
defined. So, there should be no need to do it again line above.
In C++ files it should be enough to just include curl.h, the extern "C"
linkage specification is done by libCurl itself.
Further more, extern "C" must not be used (at least when compiling with
VS 2005.
Am I right or wrong ? In case I am wrong, please point out a alterntive
solution (if available, of course :-)
Best regards,
Stefan
Received on 2008-10-01