Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've never been sold on the idea of a separate directory for headers. That aside, the <code>src</code> <code>Makefile.am</code> can simply use the <code>AM_CPPFLAGS</code> variable:</p> <pre><code>AM_CPPFLAGS = -I$(top_srcdir)/inc # and other preprocessor flags. lib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = file_1.c file_2.c ... ../inc/file_1.h ../inc/file_2.h ... </code></pre> <p>Ideally, you would also include the headers in <code>libfoo_la_SOURCES</code> as above, since any changes in a header requires the recompilation of source files. By placing the headers in the <code>src</code> directory, we can simply list <code>file_1.h</code>, <code>file_2.h</code>, etc., in the <code>SOURCES</code> primary.</p> <p>Since <code>-I$(srcdir)</code> is already provided <a href="http://www.gnu.org/software/automake/manual/automake.html#Program-Variables" rel="nofollow">automatically</a>, you don't need to add this option to <code>AM_CPPFLAGS</code>, provided the headers are included in the form <code>&lt;file_1.h&gt;</code> or <code>"file_1.h"</code>.</p> <p>Furthermore, the headers will be installed by adding the following to <code>src/Makfile.am</code>:</p> <pre><code>libfoo_includedir = $(includedir) libfoo_include_HEADERS = file_1.h file_2.h ... </code></pre> <p>A minimal top-level <code>Makefile.am</code> might look like:</p> <pre><code>ACLOCAL_AMFLAGS = -I m4 --install # AC_CONFIG_MACRO_DIR([m4]) in configure.ac SUBDIRS = src tests # depth-first ordering of build. </code></pre> <p>This leaves us with <code>test/Makefile.am</code> :</p> <pre><code>AM_CPPFLAGS = -I$(top_srcdir)/src # or $(srcdir)/../src check_PROGRAMS = foo_test foo_test_SOURCES = foo_test.c foo_test_LDADD = $(top_builddir)/src/libfoo.la </code></pre> <p>Note the use of <code>top_builddir</code> - we want to be able to build 'out-of-tree'.</p> <p>Finally, you might want to consider building libraries with headers of the form: <code>&lt;foo/file_1.h&gt;</code>. I think this is a better approach, as the leading directory provides a sort-of 'name space' for the library headers. e.g.,</p> <pre><code>libfoo_includedir = $(includedir)/foo # in foo/Makefile.am AM_CPPFLAGS = -I$(top_srcdir) # in test/Makefile.am </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload