1

I know that a lot of GNU applications use a config.h to set arguments for compile time options, like paths to resources with prefix from Autotools or Meson. For example, in some cases it is appropriate to find the location of the executable and load resources from there. Which I do on Windows and Linux. But for packaging on Linux and other UNIX based systems it seems better and usual to store the required paths inside config.h.

When and how to use config.h?

Thank you

Peter
  • 2,240
  • 3
  • 23
  • 37
  • That is entirely a matter of taste and habit, I doubt there could be any "guidelines" for something like this. – Marco Bonelli May 04 '20 at 14:22
  • even if there were guidelines, guidelines are matter of opinions. There are many instances where there exists a guideline that says "Do A" and another guideline that says "Do the opposite of A" and both can be reasonable to follow. Also asking for external ressources is off-topic – 463035818_is_not_an_ai May 04 '20 at 14:28
  • It sounds like you may have a misunderstanding of the use of `config.h`. It is not used to convey general compilation options, nor (usually) paths. It is primarily for conveying definitions of C and C++ preprocessor macros, which otherwise would be expressed on the command line via `-D` compiler options. Even very simple Autoconf setups produce a fair number of these. Other command-line options determined by `configure` are not affected. Moreover, **this is a compile-time consideration only** -- there is no difference in the resulting binaries. – John Bollinger May 04 '20 at 15:14
  • I'm asking to reopen this question. I assumed that there is maybe a GNU standard, therefore I don't request opinions. I would appreciate best practices. – Peter May 04 '20 at 16:01
  • It remains unclear *for what* you are requesting best practices, because you seem to be conflating considerations of runtime behavior with considerations of source code and build system organization. Which do you actually want to know about, and what, specifically, do you want to know? – John Bollinger May 05 '20 at 19:19

1 Answers1

0

It seems config.h is something worth thinking about and debated. There are some discussion here: and there:

Personally, I have not used it. I think the minimum is to rename it to YOURPACKAGE_config.h so that it will not be confused with another config.h from a different package.

Kemin Zhou
  • 6,264
  • 2
  • 48
  • 56
  • 1
    `config.h` should never be installed. It is a file which should only ever exist locally in the build tree, so there is no chance of name conflict with another package. If you are installing config.h, you're doing something horribly wrong. – William Pursell Apr 12 '21 at 18:12
  • @WilliamPursell good point. In the other posts, several people mentioned this. Do you mind I update my answer by adding your opinion. I agree with your view that's why I never used it and never installed it. I remember reading some books where it was used. I need to go back and read the book and check the context where it was used. – Kemin Zhou Apr 13 '21 at 17:14