0

I'm trying to use the HTML parser - Gumbo (written in C) in my C++ Builder XE6 project.

When I compile, I get many errors (E2140 Declaration is not allowed here etc.), which appear to be coming from the file char_ref.rl.

I've tried a lot to avoid these errors but I didn't succeed.

Has anyone ever used Gumbo in a C++ Builder project, or at least in a C++ project?

Thank you

Alfie J. Palmer
  • 827
  • 2
  • 15
  • 30
mvezinet
  • 99
  • 9
  • After some tests I think that the problem is that C++ builder doesn't stand the C99 while using extern "C" , since I can withdraw errors by moving the declarations... I have no idea why, and I don't know how to handle this problem (I've searched in the project options but couldn't find something relevant) – mvezinet Mar 06 '15 at 15:21
  • 1
    How do you expect anyone here to diagnose this problem when you have not shown your code or the library code that is failing. Do you think people will run off and try to install Gumbo themselves just to see what you are seeing? Please, always provide all relevant details in your questions. – Remy Lebeau Mar 06 '15 at 18:36
  • Actually, the whole code is failing, because as I said, I found out that C++ builder doesn't allow to mix statements and declarations. I can't really show here the whole code of the Gumbo library. That's why I asked for someone that already used Gombu in a C++ project. Thank you for your time however. – mvezinet Mar 09 '15 at 10:33

1 Answers1

1

Note: extern "C" doesn't mean "compile this code as C". It means that the C++ code inside the block should be compiled so that any external names etc. are published in a way compatible with the C ABI. And such a block shouldn't include any function definitions. You may be using extern "C" incorrectly in your code but it's hard to say without seeing your code.

Anyway, the C compiler part of bcc32.exe doesn't seem to allow mixed statements and declarations, even if you give the flag -An which is supposed to mean "Use C99 keywords and extensions".

You will have to either do a 64-bit build or make a whole bunch of changes to this C source for compatibility with the dinosaur that is bcc32. Or you could build Gumbo as a DLL with a modern compiler (if it supports that option, IDK).

M.M
  • 138,810
  • 21
  • 208
  • 365
  • Thank you for your answer. What I don't understand, is that mixing statements and declarations is totally fine in parts of my code where I don't use extern "C". Also, this is not in my code, but in the Gumbo code, so I'm sure it's correctly used. I definitely can't change the whole code of the Gumbo library. I guess I'll try with a DLL at first. Have a nice day. – mvezinet Mar 09 '15 at 10:39
  • @mvezinet some files in the project will be .c and some will be .cpp ; code in the .c (or included from a .c) cannot mix declarations and statements; other code can. The Gumbo code may be assuming C99 compliance or at least GCC extensions. – M.M Mar 09 '15 at 12:41