I am running Linux, Ubuntu 10.04 .
It is not the first time I try to use autotools. I did a lot of researches and follow a lot of tutorials : here is what I want to do, what I tried and what issue I am facing.
Goal :
What I tried and where I am :
The library name is FXPLib, the package name is libfxplib-0.1
My project folder is :
Makefile.am (the only one)
include
include/fxplib.h (main header)
include/FXPLib
include/FXPLib/header1.h (these are public headers)
include/FXPLib/header2.h
include/FXPLib/...
src
src/sub1/file1.c
src/sub2/file1.c
src/sub3 ...
I ran autoscan, got a configure.ac, edited it as here :
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT([libfxplib-0.1], [0.1], [<>])
AC_CONFIG_SRCDIR([src/object_system/FXP_image_s.h])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE
AM_PROG_LIBTOOL
LT_PREREQ([2.2])
LT_INIT
# Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([memset])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
I wrote Makefile.am like this :
lib_LTLIBRARIES = libfxplib-0.1.la
libfxplib_0_1_la_CFLAGS = -I$(srcdir)/include -I$(srcdir)/include/FXPLib `sdl-config --cflags --libs` -lSDL_image
libfxplib_0_1_la_SOURCES = src/sub1/file1.c \
src/sub1/file2.c \
src/sub2/file1.h \
...
nobase_include_HEADERS = include/fxplib.h \
include/FXPLib/header1.h \
include/FXPLib/header2.h \
...
ACLOCAL_AMFLAGS = -I m4
From there, everything is ok. But then I try to compile :
$ ./configure
Everything ok too...
$ make
and then I get :
...
src/graphics_engine/FXP_rendering.c:35:25: error: FXP_image_s.h: File not found
...
where :
This means : automake can compile .c files in a sub directory, but can't include in these files a private .h file that is in an other sub directory.
My problem is : How to tell automake to compile every files in every subdirectories as if they were all in the same place ?
I hope I am understandable (and sorry for some problems you could find in my words, cause I am French)
Thank you by advance.
Your configure.ac
and Makefile.am
files look like you must have put a lot of effort into learning. Congratulations! One useful tip is that you can just run autoreconf
instead of the whole chain of aclocal
, autoheader
, autoconf
, automake
, etc.
The problem in this case is actually not the autotools, but the C compiler itself - you are executing the compiler in your project's root directory to compile a file in src/sub
, but since src/sub2
is neither the current directory nor in the include path, the compiler doesn't know where to find it.
Try adding -I$(srcdir)/src/sub2
to your libfxplib_0_1_la_CFLAGS
line in Makefile.am
. This will change the include path so as to instruct the compiler to look for header files in src/sub2
, so you will have to add a similar instruction for every sub
directory containing header files used in another directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With