Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDelphiRAD StudioTech Partner

C Header Translator Tool For Delphi Lets You Parse C Header Files Using The Clang Compiler

Since Chet uses an actual compiler, you will need to have a (minimal) C develop environment installed, as well as LLVM with Clang. Clang needs to be able to find the system headers for the development environment. These will usually be available if you have some version of Visual Studio with Visual C++ installed. The free (community) edition of Visual Studio suffices.

chet

As said in the readme on Github, unlike some other header translators, Chet uses the Clang compiler to parse header files, resulting in more accurate translations that require fewer manual adjustments.

Please check out the awesome features Chet lists:

  • Translates C data types such as structs, union, enums, typedefs, procedural types and opaque types.
  • Translates C functions to Delphi procedures or functions.
  • Tries to translate #define declarations to constants where possible.
  • Generates a single .pas file for an entire directory of .h files. This reduces issues due to dependencies between header files.
  • Generates output for multiple platforms (Windows, macOS, Linux, iOS and Android) if desired.
  • You can customize the Clang parsing process by supplying command line arguments to the compiler.
  • You can customize the output of some conversion operations.
  • Retains any Doxygen style documentation comments if desired, or converts them to XmlDoc comments or PasDoc comments.
  • Provides a GUI for configuring the conversion process, and allows you to save the conversion settings to a .chet project file for reuse.

Although Chet has amazing features, there are some limitations that the user has to pay attention on:

  • Chet only works with C header files, not with C++ header files.
  • All non-inlined functions in the header files are translated and assumed to be available in the static or dynamic library for the project. This does not have to be the case. (Inlined functions are never translated since they are never available in the library.)
  • Since Clang is used to parse the header files, this means that Clangs preprocessor is run as well to perform conditional parsing (guided by #ifdef directives). This is both good and bad. It is good because it improves conversion accuracy. But it can be bad because it uses the system that Chet runs on to determine some conditional paths. For example, because Chet runs on Windows, it will parse code in #ifdef _WIN32 sections but skip any code in sections for other platforms.

You can run Chet first to check for any errors related to missing dependencies. If you get any dependency errors when running the translator, then you can download the dependencies here:

  • LLVM with Clang (Clang for Windows (64-bit) is recommended);
  • Visual Studio IDE (the free Community edition suffices; be sure to install C++ support).

You can use the pre-compiled 64-bit Windows Chet application in the Bin directory.

If you want to compile Chet yourself, then you also need libclang for Delphi and make sure the Delphi IDE can find it (the Chet project will find it automatically if the Neslib.Clang directory is at the same level as the Chet directory).

Chet is licensed under the Simplified BSD License.

From the Github article we understand that Chet is pretty straightforward. In many cases, you only need to provide a directory with header files, the name of the output .pas file and select “Run Header Translator (F9)”.

For more control over the conversion process, you can specify various options, described below. The screenshot from GitHub for the project is below:

chet screenshot 2

This is for sure the best header files parser, so if you want to check it, go to the link below and download it:

https://github.com/neslib/Chet

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

3 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES