0

I've to build a static library, with some predefined functions and I need also some auxiliary functions.

A requirement is: Your library may not provide any global symbols other than function names.

I understood that the functions should only be available within one module of the library. This means that the functions should be static. How can I declare static functions in a header?

I've found a solution for inline functions in this topic: function used but not defined "If they are used in multiple C files, declare them static and have their definition in an included header file. That allows all .c files that include that header to have their own private definition of the function, which allows the compiler to inline it. Lone static function prototypes make little to no sense in a header file that will be used by multiple source files, since their actual definitions will be missing." But how does that work with normal functions?

naicul
  • 1
  • Why do you think you need static functions in a header for what you are trying to do? The requirement allows you to have global functions. Can you show some code example where you think you need to do this? – kaylum Feb 01 '20 at 09:23
  • I understood the restriction so that the auxiliary functions should only work within a module and not as "individual/single standing" functions. I thought it worked with a static function. – naicul Feb 01 '20 at 09:26
  • I don't understand what you mean by "auxiliary functions" and "individual/single standing functions". Please show code to illustrate what you are asking. You can declare static functions in the C file. You probably don't need to declare static functions in the header. – kaylum Feb 01 '20 at 09:27
  • For example, a function is specified that can merge two lists. I then defined an additional function that concatenated both lists. This concatenate function should only work in this library. – naicul Feb 01 '20 at 09:31
  • Then declare it static in the C file where it is used. There is no need to put that in the header file. – kaylum Feb 01 '20 at 09:33
  • And if i need this function also in another C file? Thank you for your help :) – naicul Feb 01 '20 at 09:34
  • One way is to restructure your code so that the static function is only needed in one C file. Or you can just define the whole function as static in the header - but that is not best practice in most cases. There are ways to change the visibility of symbols in a shared library: [see this](https://stackoverflow.com/questions/435352/limiting-visibility-of-symbols-when-linking-shared-libraries). But I'm not sure that's really want your requirement is intending for you to do. – kaylum Feb 01 '20 at 09:39
  • I'll have a look, thank you :) – naicul Feb 01 '20 at 10:07

0 Answers0