0

I'm using mongoose to build an HTTP server in C++, and I'm getting an error message when I try to include other files in my program:

/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdint:183:8: error: 
  expected unqualified-id
using::intptr_t;
   ^
/Users/cs/Downloads/mongoose-master/mongoose.c:2415:18: note: 
expanded from
  macro 'intptr_t'
#define intptr_t long
             ^

This happens whenever I attempt include the following files in my program:

#include <string> 
#include <vector>
#include <cstring>
#include <iostream>
#include <iterator>
#include <sstream>

I've tried to narrow it down to one of these files causing the problem by commenting out some of them, but it appears that any one of them causes the error. Interestingly enough, string.h does not cause the error.

ageispolis
  • 33
  • 7
  • It seems like the mongoose library is defining a macro that collides with types in the standard library. Can you give a simple, complete example showing the order of your includes? One solution may be to reorder your includes to place the mongoose.h after the standard library files, but in this case, it seems like the macro is defined in mongoose.c, which should *not* influence other translation units. – NicholasM Nov 23 '19 at 21:18
  • @NicholasM That fixed it! Thanks so much! I figured it had something to do with a conflicting macro. – ageispolis Nov 23 '19 at 21:20
  • Are you #include-ing mongoose.c at any point? It's generally not recommended to do that with .c or .cpp files. – NicholasM Nov 23 '19 at 21:22
  • Yes, and I moved both the .c and .h files after the other include statements, which made it work. Is it not good practice to include .c files? The reason why I felt the need was that it's a .c file and not .cpp, it felt strange compiling them both in g++ but it works. – ageispolis Nov 23 '19 at 21:24

1 Answers1

0

It sounds like your source code contains something like this:

#include <mongoose.c>

The .c file defines a macro that collides with words used in the standard library headers.

Including a .c file is not a good practice. Instead, you should build the mongoose library, and link your program against it.

If you really have to keep everything in a single translation unit, you should be able to move that dubious include statement to after all other headers, or even to the bottom of your cpp file.

But it would be best to figure out how to build mongoose.c separately, then link against the resulting library. You can ask a separate question, or see if you get anything out of this: Can't figure out how to build C application after adding Mongoose Embedded

NicholasM
  • 4,557
  • 1
  • 20
  • 47
  • Thanks. Thankfully the mongoose library is simple enough such that you only need to build mongoose.c and include mongoose.h. – ageispolis Nov 23 '19 at 21:47