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

StackOverflow https://stackoverflow.com/questions/11362226

  •  19-06-2021
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top