2
votes

I am new to autotools and have tried to code up an example. I am creating one library and linking it against another object.

My problem is that the Makefile that is generated for the library seems to be mis-interpreted as C code, but is actually C++. If I replace all occurences of ".c" to ".cpp" in the generated Makefile, all is well.

I am using libtool 2.4.2 and autoconf 2.69. My code structure is listed below:

test/
 - Makefile.am
 - configure.ac
 include/
  - mylib.hh
 src/
   hw/
    - Makefile.am
    - main.cpp
   mylib/
    - Makefile.am
    - mylib.cpp

Below is my top level Makefile.am:

ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src/mylib src/hw

configure.ac

AC_PREREQ([2.65])    
AC_INIT([hw],[1.0.0],[[email protected]])

# directories (relative to top-level) to look into for AutoConf/AutoMake files
AC_CONFIG_MACRO_DIR([m4])
# enable AutoMake
AM_INIT_AUTOMAKE([1.10])
# all defined C macros (HAVE_*) will be saved to this file
AC_CONFIG_HEADERS([config.h])

AC_PROG_CC
AM_PROG_CC_C_O

# Check if you have a C++ compiler
AC_PROG_CXX
AC_PROG_CXX_C_O

AC_PROG_INSTALL

## Initialize GNU LibTool
LT_INIT

AC_CONFIG_FILES([Makefile
             src/hw/Makefile
             src/mylib/Makefile])
AC_OUTPUT

src/hw/Makefile.am

ACLOCAL_AMFLAGS = -I m4
bin_PROGRAMS = hw

hw_SOURCES = main.cpp
AM_CPPFLAGS = -I$(top_srcdir)/include
hw_LDADD = $(top_srcdir)/src/mylib/libmylib.la

src/mylib/Makefile.am

ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libmylib.la
libmylib_la_sources = mylib.cpp
libmylib_la_CPPFLAGS = -I$(top_srcdir)/include

The error I get when running make:

make[2]: *** No rule to make target 'libmylib.c', needed by 'libmylib_la-libmylib.lo'.  Stop.

Once again, substituting ".cpp" for all occurrences of ".c" in the generated src/mylib/Makefile, the code compiles, links and runs fine. Any help is appreciated.

1

1 Answers

1
votes

Did you try changing:

libmylib_la_sources = mylib.cpp

to

libmylib_la_SOURCES = mylib.cpp

(upper case SOURCES)? m4 is case-sensitive.