PCRE-related compiler errors

Posted by Silverwind on Thu 18 Apr 2013 10:43 PM — 21 posts, 90,736 views.

#0
Working with source for 4.90, attempting to compile with MSVC++ 6.0 with service pack 6.0 installed, the compiler tosses the following errors:

Utilities.cpp
[...]mushclient\pcre\pcre_internal.h(2327) : error C2371: 'real_pcre' : redefinition; different basic types
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'
[...]mushclient\pcre\pcre_internal.h(2328) : error C2371: 'real_pcre16' : redefinition; different basic types
        [...]mushclient\pcre\pcre.h(312) : see declaration of 'real_pcre16'
[...]mushclient\pcre\pcre_internal.h(2351) : error C2027: use of undefined type 'real_pcre'
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'
[...]mushclient\Utilities.cpp(2590) : error C2027: use of undefined type 'real_pcre'
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'
[...]mushclient\Utilities.cpp(2590) : error C2227: left of '->options' must point to class/struct/union
lua_scripting.cpp
[...]mushclient\scripting\..\pcre\pcre_internal.h(2327) : error C2371: 'real_pcre' : redefinition; different basic types
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'
[...]mushclient\scripting\..\pcre\pcre_internal.h(2328) : error C2371: 'real_pcre16' : redefinition; different basic types
        [...]mushclient\pcre\pcre.h(312) : see declaration of 'real_pcre16'
[...]mushclient\scripting\..\pcre\pcre_internal.h(2351) : error C2027: use of undefined type 'real_pcre'
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'
[...]mushclient\scripting\lua_scripting.cpp(518) : error C2027: use of undefined type 'real_pcre'
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'
[...]mushclient\scripting\lua_scripting.cpp(518) : error C2227: left of '->options' must point to class/struct/union
Generating Code...
Error executing cl.exe.

MUSHclient.exe - 10 error(s), 0 warning(s)
Australia Forum Administrator #1
I seem to recall getting this a year or so ago but can't remember how I fixed it. I note that:


#if defined COMPILE_PCRE8
#define REAL_PCRE real_pcre
#elif defined COMPILE_PCRE16
#define REAL_PCRE real_pcre16
#elif defined COMPILE_PCRE32
#define REAL_PCRE real_pcre32
#endif


Try changing "real_pcre" to "REAL_PCRE", see if that helps.
#2
That didn't work. It still throws the exact same errors on all the same lines.
Australia Forum Administrator #3
I'm using Visual C++ 6.0.

It should compile OK.
Australia Forum Administrator #4
Which version of PCRE do you have?
#5
The one from the readme in the PCRE directory for the source:

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.zip
#6
Any further ideas for this? I don't know what I could be doing wrong here. I've checked and doublechecked all the instructions in the Mushclient source package.
Australia Forum Administrator #7
I did a "diff" on the changes between what I actually compiled with, and the 8.32 release:


diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_compile.c pcre/pcre_compile.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_compile.c	Sun Nov 11 21:23:00 2012
--- pcre/pcre_compile.c	Wed Feb  6 08:49:15 2013
***************
*** 1,3 ****
--- 1,10 ----
+ #pragma warning( disable : 4018)  // '<' : signed/unsigned mismatch
+ #pragma warning( disable : 4127)  // conditional expression is constant
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ #pragma warning( disable : 4701)  // local variable 'othercase' may be used without having been initialized
+ #pragma warning( disable : 4702)  // unreachable code
+ 
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/
diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_dfa_exec.c pcre/pcre_dfa_exec.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_dfa_exec.c	Sun Nov 11 21:23:00 2012
--- pcre/pcre_dfa_exec.c	Wed Feb  6 09:11:11 2013
***************
*** 1,3 ****
--- 1,6 ----
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ #pragma warning( disable : 4146)  // unary minus operator applied to unsigned type, result still unsigned
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/
diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_exec.c pcre/pcre_exec.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_exec.c	Sun Nov 11 21:23:00 2012
--- pcre/pcre_exec.c	Wed Feb  6 08:50:10 2013
***************
*** 1,3 ****
--- 1,6 ----
+ #pragma warning( disable : 4127)  // conditional expression is constant
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/
diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_maketables.c pcre/pcre_maketables.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_maketables.c	Wed Oct 17 17:14:00 2012
--- pcre/pcre_maketables.c	Wed Feb  6 08:49:38 2013
***************
*** 1,3 ****
--- 1,5 ----
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/
diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_ord2utf8.c pcre/pcre_ord2utf8.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_ord2utf8.c	Sun Nov 11 21:23:00 2012
--- pcre/pcre_ord2utf8.c	Wed Feb  6 08:49:44 2013
***************
*** 1,3 ****
--- 1,5 ----
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/
diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_refcount.c pcre/pcre_refcount.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_refcount.c	Wed Oct 17 17:14:00 2012
--- pcre/pcre_refcount.c	Wed Feb  6 08:49:50 2013
***************
*** 1,3 ****
--- 1,5 ----
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/
diff -c /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_study.c pcre/pcre_study.c
*** /c/Documents and Settings/Owner/Desktop/pcre-8.32/pcre_study.c	Sun Nov 11 21:23:00 2012
--- pcre/pcre_study.c	Wed Feb  6 08:49:55 2013
***************
*** 1,3 ****
--- 1,5 ----
+ #pragma warning( disable : 4244)  // conversion from 'int' to 'unsigned short', possible loss of data
+ 
  /*************************************************
  *      Perl-Compatible Regular Expressions       *
  *************************************************/


Nothing looks really relevant.

The only thing I can think of is the precompiled headers. Select all the PCRE files in the IDE and make sure that you have "Not using precompiled headers" selected.
Amended on Mon 13 May 2013 12:23 PM by Nick Gammon
#8
Those are all set up as they should be. :/ It confuses the hell out of me that files straight from the package are conflicting with /themselves/. Is there anything else that could be relevant here? I'm using MSVC++ 6.0 with Service Pack 6 on 64-bit Windows 7.
Australia Forum Administrator #9
I'm confused too because that is the compiler I have, and if you have the 4.90 source that is what I am using.

Can you confirm that in Utilities.cpp around line 2590 you have this exact code?


typedef unsigned char uschar;

int
njg_get_first_set(const pcre *code, const char *stringname, const int *ovector)
{
const real_pcre *re = (const real_pcre *)code;
int entrysize;
char *first, *last;
uschar *entry;
if ((re->options & (PCRE_DUPNAMES | PCRE_JCHANGED)) == 0)
  return pcre_get_stringnumber(code, stringname);
entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last);
if (entrysize <= 0) return entrysize;
for (entry = (uschar *)first; entry <= (uschar *)last; entry += entrysize)
  {
  int n = (entry[0] << 8) + entry[1];
  if (ovector[n*2] >= 0) return n;
  }
return (first[0] << 8) + first[1];
}

Australia Forum Administrator #10
Also did you do this step in the "readme" for the PCRE part of the project?

Quote:


(Note that config.h is part of the git repository)

4. Rename pcre_chartables.c.dist as pcre_chartables.c
Rename pcre.h.generic as pcre.h

#11
Check and doublecheck. The compiler isn't even producing an error within utilities.cpp itself, it's a conflict between pcre.h and pcre_internal.h, both of which come from the PCRE package. I don't understand how with the same compiler, using the same sources and project files that this could be going on.
Australia Forum Administrator #12
It is here:


[...]mushclient\Utilities.cpp(2590) : error C2027: use of undefined type 'real_pcre'
        [...]mushclient\pcre\pcre.h(309) : see declaration of 'real_pcre'


It says it is undefined, and then points to pcre.h line 309:


struct real_pcre8_or_16;                 /* declaration; the definition is private  */


OK, so that is a forwards declaration. However the real declaration seems to be at line 2309 of pcre_internal.h.


typedef struct real_pcre8_or_16 {
  pcre_uint32 magic_number;
  pcre_uint32 size;               /* Total that was malloced */
  pcre_uint32 options;            /* Public options */
  pcre_uint16 flags;              /* Private flags */
  pcre_uint16 max_lookbehind;     /* Longest lookbehind (characters) */
  pcre_uint16 top_bracket;        /* Highest numbered group */
  pcre_uint16 top_backref;        /* Highest numbered back reference */
  pcre_uint16 first_char;         /* Starting character */
  pcre_uint16 req_char;           /* This character must be seen */
  pcre_uint16 name_table_offset;  /* Offset to name table that follows */
  pcre_uint16 name_entry_size;    /* Size of any name items */
  pcre_uint16 name_count;         /* Number of name items */
  pcre_uint16 ref_count;          /* Reference count */
  const pcre_uint8 *tables;       /* Pointer to tables or NULL for std */
  const pcre_uint8 *nullpad;      /* NULL padding */
} real_pcre8_or_16;

Amended on Fri 17 May 2013 05:49 AM by Nick Gammon
Australia Forum Administrator #13
Try setting this define in project properties, if you haven't already:



For each of the .c file in the PCRE part, as highlighted (there would be a few more underneath).
Amended on Fri 17 May 2013 05:57 AM by Nick Gammon
#14
Already set across the board. :( I'm using the project/workspace files from the source package.
Australia Forum Administrator #15
All I can suggest is that you do a Build -> Clean (to get rid of extraneous files) and then zip up your entire source directory and put it somewhere I can download it and I'll try to compile it, in case there is a file that should be in source control but isn't.

If you don't have anywhere suitable send me a forum message and I'll give you my email address (it's pretty obvious).
#16
I feel a little stupid but I neglected to notice that we got to a second page here. Sorry for the long wait.

Here's the source I have, all packed up: http://depositfiles.com/files/houayytq0
Australia Forum Administrator #17
I can reproduce your problem. To fix:

In pcre.h at lines 309 to 313 change:


struct real_pcre;                 /* declaration; the definition is private  */
typedef struct real_pcre pcre;

struct real_pcre16;               /* declaration; the definition is private  */
typedef struct real_pcre16 pcre16;


to:


struct real_pcre8_or_16;                 /* declaration; the definition is private  */
typedef struct real_pcre8_or_16 pcre;

struct real_pcre8_or_16;               /* declaration; the definition is private  */
typedef struct real_pcre8_or_16 pcre16;


Then it compiles OK.
Australia Forum Administrator #18
I'm trying to work out why it took so long to notice that. I see that pcre.h is not under source control (git) so I must have used the one from the PCRE distribution, got the error, and then made the change I mentioned above. But not being under source control, it wasn't documented. Checking my directory against the release shows the same change (and only that):


*** C:\Documents and Settings\Owner\Desktop\pcre-8.32\pcre.h.generic	Fri Nov 30 11:50:00 2012
--- pcre.h	Wed Feb  6 09:08:23 2013
***************
*** 306,316 ****
  
  /* Types */
  
! struct real_pcre;                 /* declaration; the definition is private  */
! typedef struct real_pcre pcre;
  
! struct real_pcre16;               /* declaration; the definition is private  */
! typedef struct real_pcre16 pcre16;
  
  struct real_pcre32;               /* declaration; the definition is private  */
  typedef struct real_pcre32 pcre32;
--- 306,316 ----
  
  /* Types */
  
! struct real_pcre8_or_16;                 /* declaration; the definition is private  */
! typedef struct real_pcre8_or_16 pcre;
  
! struct real_pcre8_or_16;               /* declaration; the definition is private  */
! typedef struct real_pcre8_or_16 pcre16;
  
  struct real_pcre32;               /* declaration; the definition is private  */
  typedef struct real_pcre32 pcre32;
Amended on Wed 29 May 2013 06:05 AM by Nick Gammon
Australia Forum Administrator #19
Documented now:

https://github.com/nickgammon/mushclient/commit/f12ef5b21df
#20
Awesome, got it now. Thanks a lot for the support.