Lorenzo Bettini wrote:
on the manual I read
"These Gnulib substitute header files rely on<config.h> being already
included. Furthermore<config.h> must be the first include in every
compilation unit. This means that to all your source files and likely
also to all your tests source files you need to add an ‘#include
<config.h>’ at the top. Which source files are affected? Exactly those
whose compilation includes a ‘-I’ option that refers to the Gnulib
library directory. "
This paragraph is correct.
Would it be correct to put config.h only say in file1.cpp (and use the
‘-I’ option that refers to the Gnulib library directory for that file
only), and not in file2.cpp and file3.cpp (where I don't use -I to
refer
to gnulib library directory), and then link all the 3 files
together by
also putting -lgnu?
This will work find as long as data types defined in system headers
defined by
gnulib (such as structs, function pointers, pointers to socklen_t,
etc.)
are
not exchanged between file1.cpp on one side and file2.cpp and
file3.cpp on
the
other side.
For example, if file1.cpp passes a 'struct stat' to file2.cpp
through some
function call or global variable, then you must be aware that the
'struct
stat'
that file1.cpp sees is 64-bit safe and therefore larger than the 32-bit
'struct stat' that file2.cpp sees. Similarly for 'struct
sched_param' in
<sched.h> and others. Typically this leads to crashes that are very
hard
to
debug because the source code suggests to you that the two 'struct
stat's
are the same when they are not.