8
./theheader.h:349: Error: Syntax error in input(3).

Offending line:

string read_gdbm(GDBM_FILE dbf, string key_str, bool show_err = gbls.verbose);

Any ideas?

Awalias
  • 2,027
  • 6
  • 31
  • 51

4 Answers4

5

Typically, a syntax error in SWIG means that it can't understand the line in question (which can be annoying, because the line numbers don't follow macros such as %defines). So I suggest you check that string (should it be std::string? has it been defined?), GDBM_FILE (has it been defined? should it be in a namespace?) and maybe gbls.verbose (has it been defined?) make sense to SWIG. It may help to run swig with the -E option (be sure to redirect the stdout), find the corresponding line and search backward for each type involved. You may need to add some #includes.

Also check the previous line, to ensure you're not missing a semicolon, or something like that.

Paul Price
  • 2,657
  • 30
  • 26
4

As a side note, I've run into the same issue for different reasons: I was trying to use a vector < vector < double >>. Now the ">>" character sequence mustn't be used with templates according to the C++99 standard, hence the swig error message popped up. The solution was to simply add an extra space to separate them.

  • THANK YOU SO MUCH. I had no clue why it was saying the my 2d vector had an invalid issue. I would have never figured this out. – bitbytten Jun 30 '22 at 15:24
2

I hit a similar error. I'll clarify my process, hope it can be helpful.

lib.i:

...
%begin %{
#include "header1.h"
%}
...

%include "header1.h"

header1.h:

19 typedef struct T {
   ...
23 } PACKED TlvHdr;

The error message just as below

./header1.h:23: Error: Syntax error in input(3).

I check the SWIG doc(http://www.swig.org/Doc1.3/SWIG.html 5.7.1) and found that the syntax error is so common, it's probably caused by a SWIG bug.

The doc recommended when encountering a syntax error to use #ifndef SWIG to omit statements that will make SWIG parser issue an error. So I changed the header1.h file, then the error disappeared.

header1.h:

#ifndef SWIG
19 typedef struct T {
   ...
23 } PACKED TlvHdr;
#endif

If you can't modify theheader.h file, you can make a new header file that just contains the declarations you need and replace the file from theheader.h to your new header file at %include directive

Anton Menshov
  • 2,266
  • 14
  • 34
  • 55
1

I had a similar issue and -E helped me understand that a macro definition was hidden inside an #ifndef SWIG block. I suspect that here it does not see the definition of GDBM_FILE, likely because it does not recurse.

Community
  • 1
  • 1
Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109