4

Basically, I am asking, whether my code should say

#include “../libs/src/my_lib.h”

or

#include “my_lib.h”

with a complier option of

-I ../libs/src/   

I feel (reasonably strongly) that the former is preferable, because:

  • it is independent of build system
  • it specifies exactly which “my_lib” is meant, in case there are several.

My current project uses the latter style, with -I in the project file, saying that:

  • we will never change build system, compiler or platform
  • every file has a unique name

That actually sounds reasonable, so I wonder if I am just being influenced by opinion, or whether there is any technical reason (not an opinion) to prefer one approach over the other.

2
  • 6
    I don't think it's appropriate to view your build system as separate from your project. Your Makefiles (or equivalents) are part of the code. With that, your question could be reframed as “should I put the information about library location into one central place, or spread it across the whole project?” → see Caleth's answer :)
    – amon
    Commented Nov 27, 2018 at 14:24
  • I agree with "I don't think it's appropriate to view your build system as separate from your project" (+1). I was thinking of re-use, particularly cross platform. I somewhat like your rephrasing about "central vs strewn", but that loses a few details, like being able to know which "inc.h" is meant, if there are several of that name in the project (bad practise, I know)
    – Mawg
    Commented Nov 27, 2018 at 15:15

1 Answer 1

9

In my current workplace, various projects are using boost versions ranging from 1.60 to 1.66, and at appropriate times we move those forward. It's much simpler to repoint the project includes to a different folder and leave all the #includes alone.

These projects are cross platform, we are using multiple compilers. Each compiler has some equivalent of -I ../libs/src/, and we use qmake to coordinate them all.

As amon notes in a comment,

I don't think it's appropriate to view your build system as separate from your project. Your Makefiles (or equivalents) are part of the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.