0

I am using apr in a C program, I am including the appr_error.h header file, but I am getting an error during building:

In function ‘APR_DECLARE’: error: expected declaration specifiers before ‘apr_strerror’

Here is the offending line in the header file:

 /**
  * Return a human readable string describing the specified error.
  * @param statcode The error code the get a string for.
  * @param buf A buffer to hold the error string.
  * @param bufsize Size of the buffer to hold the string.
  */
 APR_DECLARE(char *) apr_strerror(apr_status_t statcode, char *buf, 
                                  apr_size_t bufsize);

This header file include a header file that has a #define for APR_DECLARE as follows:

#if !defined(WIN32)
368 /**
369  * The public APR functions are declared with APR_DECLARE(), so they may
370  * use the most appropriate calling convention.  Public APR functions with 
371  * variable arguments must use APR_DECLARE_NONSTD().
372  *
373  * @deffunc APR_DECLARE(rettype) apr_func(args);
374  */
375 #define APR_DECLARE(type)            type

I am confused as to why I am getting this error message - any ideas?

Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
  • I think this is because apr.h does not appear to be using include guards. But surely, this can't be the cause - afterall, the code is from the Apache foundation; i.e. somebody must have spotted this already?. I don't want to edit the Apache code to add include guards (its more likely I am making a mistake here than the Apache team). – Homunculus Reticulli Jul 06 '12 at 12:42

1 Answers1

1

Your compiler flags are likely off, especially for where to search for include files.

apr comes with the apr-config tool (or possibly apr-1-config), which you're supposed to run and use for compiler and linker flags

e.g.

# apr-config  --cflags  --includes
  -pthread -I/usr/include/apr-0

Tells me I have to pass -pthread -I/usr/include/apr-0 when compiling C code that is using APR .

There is further information on pkg-config here.

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
nos
  • 223,662
  • 58
  • 417
  • 506