I am new to using the Unix 'make' package and I have a question regarding header files and functions in header files.
I have been told that it is good practice to put object declarations and definitions in a header file.
I also have some (custom made (non library)) functions ( I use c++ for scientific computing) that I use in several programs. So for convenience when I use make these will be in a separate c++ file (one for each function).
Now here is my problem: I use one of these functions within my object definition. The only way I can seem to get make to work is to put this function into the object file as a friend function.
It would be more desirable to link this function to the header file (and therefore object) so that the files remain separate.
Is there any way to do this? Is this a reasonable expectation or even a good thing to do?
I hope that made sense.
Thank you in advance.
I'm not sure on how you've gone from the placement of utility functions to making things friends. The two are independent.
If you have a (growing) set of useful functions, it's common to place them in a library. Your applications can link to that library, to pick up these functions, along with all the other libraries.
From a make perspective, you'll need to organise your library code and header files in a seperate directory and build the library there. You then install the library to make it available to the environment, and then build the applications.