Am I using libtool correctly?
Asked Answered
B

1

5

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 :

  • compile (and then cross-compile, but this will be an other job) my own library coded in C using libtool, autoconf and automake

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
    
  • Then I ran aclocal and autoheader to get files needed by automake
  • Then the most important : autoconf
  • And : automake --add-missing --copy

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 :

  • "graphics_engine" is equivalent to src/sub
  • "FXP_rendering.c" to src/sub/file.c
  • "FXP_image_s.h" to src/sub2/header.h

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.

Belovo answered 12/3, 2011 at 22:22 Comment(4)
You have an excellent formatted and detailed question here, too bad I cannot help you with an answer.Wales
Thank you. It's a very specific question : should I try to post it on the "Expert Programmer" stackexchange site ?Verde
All right ! Is there any way to put this thread "up" tomorrow when more people will be logged in ?Verde
meta.stackexchange.com/questions/7046/…Wales
E
8

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.

Explicit answered 13/3, 2011 at 11:17 Comment(4)
Thank you for your answer. I knew that this method would help me, but I have 8 subdirectories and I thought it would be too much. I tried this : mega-nerd.com/erikd/Blog/CodeHacking/nonrecursive_automake.html but it doesn't seam to work with me. If there is no other solution, I will do what you say.Verde
This worked for me ! Thank you very much. Finally it's not a so bad idea than I thought. I hope it will be useful for other guys trying to manage with autotools !Verde
Great! You can still do it the way they say in the blog, but the key to getting it to work is the line they quote there, #include <path/to/header.h>, and the paragraph after it. If you do all your includes like that, then it will work for you too, since the compiler will know where to look for all the headers. I thought about putting that in my answer, but I thought it would get unnecessarily complicated.Explicit
Ok ! I thought it was a way NOT to write <path/to/header.h> in my sources ! But now it works so I can begin to improve my autotools scripts ! Thank you !Verde

© 2022 - 2024 — McMap. All rights reserved.