Automake Libtool 'No rule to make target' - c++

I've been trying to build to GLTools library that accompanies The OpenGL SuperBible into a libtool library with automake.
I've set up autoconf and automake but when it comes to actually build the library I get:
$ make
make: *** No rule to make target `GLBatch.lo', needed by `libgltools.la'. Stop.
I've searched google as much as my sanity will let me and come up with nothing, I'm new to automake so I'm not quite sure what to be searching for. I'm sure it's either a tiny mistake or I've missed something fundamental.
Here is my Makefile.am:
ACLOCAL_AMFLAGS = -I m4
lib_LTLIBRARIES = libgltools.la
libgltools_la_SOURCES = GLBatch.cpp GLShaderManager.cpp GLTriangeBatch.cpp GLTools.cpp math3d.cpp glew.c
#libgltools_la_CFLAGS =
libgltools_la_LIBADD = -lX11 -lglut -lGL -lGLU -lm
include_HEADERS = GLBatchBase.h GLBatch.h GLFrame.h GLFrustum.h GLGeometryTransform.h GLMatrixStack.h GLShaderManager.h GLTools.h GLTriangleBatch.h math3d.h StopWatch.h GL/glew.h GL/glxew.h GL/wglew.h
EXTRA_DIST = autogen.sh
And my configure.ac if it matters:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([libgltools.la], [0.1], [jon.hatchett#gmail.com])
AM_INIT_AUTOMAKE([libgltools.la], [0.1])
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_HEADERS([include/config.h])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lGL':
AC_CHECK_LIB([GL], [main])
# FIXME: Replace `main' with a function in `-lGLU':
AC_CHECK_LIB([GLU], [main])
# FIXME: Replace `main' with a function in `-lX11':
AC_CHECK_LIB([X11], [main])
# FIXME: Replace `main' with a function in `-lglut':
AC_CHECK_LIB([glut], [main])
# FIXME: Replace `main' with a function in `-lm':
AC_CHECK_LIB([m], [main])
# Checks for header files.
AC_PATH_X
AC_CHECK_HEADERS([inttypes.h stddef.h stdint.h stdlib.h string.h sys/time.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT64_T
AC_CHECK_TYPES([ptrdiff_t])
# Checks for library functions.
AC_HEADER_MAJOR
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gettimeofday sqrt strchr strstr])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
Thanks very much.

It's hard to say based on your description but I would wager that you need to put your Makefile.am in the src directory and then create a Makefile.am in the GLTools directory that looks like this:
SUBDIRS = src
ACLOCAL_AMFLAGS = -I m4
It is also possible to do a non-recursive make but that requires some extra setup.
Here I did it for you:
https://github.com/msteinert/gltools

You should add somewhere in your configure.ac file:
LT_INIT
LT_LANG([C++])
Or alternatively, according to the docs:
LT_INIT
AC_PROG_CXX

Related

Issue with autotools and generating a c++ library

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],[foo.bar#example.com])
# 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.
Did you try changing:
libmylib_la_sources = mylib.cpp
to
libmylib_la_SOURCES = mylib.cpp
(upper case SOURCES)? m4 is case-sensitive.

Adding Linker Flag to configure.ac

I want to add --export-dynamic flag to my project's configure.ac file.
I am trying to compile my project files that must use this flag after pkg-config --cflags --libs gtk+-3.0.
The following are contents of my configure.ac file.
AC_INIT(myapp, 1.0)
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([1.11])
AM_SILENT_RULES([yes])
AC_PROG_CXX
AC_PROG_CC
IT_PROG_INTLTOOL([0.35.0])
GETTEXT_PACKAGE=myapp
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name])
AM_GLIB_GNU_GETTEXT
LT_INIT
PKG_CHECK_MODULES(MYAPP, [gtk+-3.0 ])
AC_OUTPUT([
Makefile
src/Makefile
po/Makefile.in
])
How do I do that?
How about adding them to AM_LDFLAGS or more specific _LDFLAGS variable in Makefile.am

C++ Access Autoconf Variable Datadir

I am creating a program called spellcheck, and I'm using autoconf and automake to create a build system for it. The program relies on the dictionary 'english.dict', which is in the data directory (based on whatever prefix the user selected). I want the data directory path accessible by spellcheck, so I created a custom variable that contained its value:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(libspellcheck, 1.25, corinthianmonthly#hotmail.com)
AC_OUTPUT(Makefile libspellcheck/Makefile spellcheck/Makefile man/Makefile)
AC_CONFIG_SRCDIR([])
AC_CONFIG_HEADERS([config.h])
AC_DEFINE_UNQUOTED([DATA_PATH], ["$pkgdatadir"],"DData Directory Path")
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h,iostream,fstream,string,stdio.h,sstream,cctype,algorithm,boost/algorithm/string.hpp])
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
AC_TYPE_SIZE_T
# Checks for library functions.
AC_OUTPUT
However, in the config.h file, this value is blank:
/* config.h. Generated from config.h.in by configure. */
/* config.h.in. Generated from configure.ac by autoheader. */
/* "Description" */
#define DATA_PATH ""
...
I tried changing $pkgdatadir to $datadir, but I got the same result. What am I doing wrong, or is what I am trying to achieve impossible?
EDIT: I redefined the variable in my Makefile.am for spellcheck:
AM_CFLAGS = -DDATA_PATH=\"$(pkgdatadir)\" -m32 -Wall
bin_PROGRAMS = spellcheck
pkgdata_DATA = english.dict
spellcheck_SOURCES = spellcheck.cpp meta.cpp
spellcheck_LDADD = ../libspellcheck/libspellcheck.a
But now it complains about DATA_PATH being nonexistant:
spellcheck.cpp:4:22: error: 'DATA_PATH' was not declared in this scope
#define DEFAULT_DICT DATA_PATH "english.dict"
Because now it seems to be ignoring all CFLAGS:
g++ -DHAVE_CONFIG_H -I. -g -O2 -MT spellcheck.o -MD -MP -MF .deps/spellcheck.Tpo -c -o spellcheck.o spellcheck.cpp
It turns out that I needed to use AM_CPPFLAGS rather than CFLAGS.

Determine library path programmatically in Makefile

I'm new to makefile, and I'm writing a simple C++ shared library.
Is there a way of finding a library's path dynamically by the makefile itself? What I want is something like this: (in my makefile)
INCLUDE_DIRS := `which amplex-gui`
LIBRARY_DIRS := `which amplex-gui`
amplex-gui is a library I use in my code, and I need to put its lib and include directories in my makefile. I want to figure out its path dynamically because each user might install it in a different path on their machine. Therefore, I need my makefile to dynamically parse the which command (or perhaps the $PATH environment variable) to find that path. How can I go about doing this?
Remember that backquoting is shell syntax. Make doesn't do anything special with backquotes. If you're using GNU make, you can use $(shell which amplex-gui) to get equivalent behavior as backquotes.
Regarding your comment above, I'm not sure exactly what you mean by "nest commands", but you can definitely use the shell's $() syntax within a make shell function. However, as with all strings that make expands, you need to double the dollar signs to quote them so that they are passed to the shell. So for example:
INCLUDE_DIRS := $(shell echo $$(dirname $$(dirname $$(which amplex-gui))))
Of course you can also use make functions; unfortunately the make dir function is annoying in that it leaves the final slash, so it cannot be used multiple times directly. You have to put a patsubst in there, like:
INCLUDE_DIRS := $(dir $(patsubst %/,%,$(dir $(shell which amplex-gui))))
Finally, if you have a sufficiently new version of GNU make there's the abspath function, so you could do something like this:
INCLUDE_DIRS := $(abspath $(dir $(shell which amplex-gui))../..)

Including dynamic libraries using automake and autoconf

I am trying to include some dynamic libraries (.so files) for a simple 3D game I am making on linux using C++. These dynamic libraries are for using the Bullet physics engine.
I have very limited knowledge of how use automake and autoconf so any help would be much appreciated.
How might I modify any of the following files to include these dynamic libraries?
Here is my makefile.am:
noinst_HEADERS= BaseApplication.h Physics.h GameApplication.h
bin_PROGRAMS= OgreApp
OgreApp_CPPFLAGS= -I$(top_srcdir)
OgreApp_SOURCES= BaseApplication.cpp Physics.cpp GameApplication.cpp
OgreApp_CXXFLAGS= $(OGRE_CFLAGS) $(OIS_CFLAGS)
OgreApp_LDADD= $(OGRE_LIBS) $(OIS_LIBS)
EXTRA_DIST = buildit makeit
AUTOMAKE_OPTIONS = foreign
Here is my configure.ac:
AC_INIT(configure.ac)
AM_INIT_AUTOMAKE(SampleApp, 0.1)
AM_CONFIG_HEADER(config.h)
AC_LANG_CPLUSPLUS
AC_PROG_CXX
AM_PROG_LIBTOOL
PKG_CHECK_MODULES(OGRE, [OGRE >= 1.2])
AC_SUBST(OGRE_CFLAGS)
AC_SUBST(OGRE_LIBS)
PKG_CHECK_MODULES(OIS, [OIS >= 1.0])
AC_SUBST(OIS_CFLAGS)
AC_SUBST(OIS_LIBS)
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
I also have a buildit file that sets everything in motion:
#!/bin/sh
rm -rf autom4te.cache
libtoolize --force --copy && aclocal && autoheader && automake --add-missing --force-missing --copy --foreign && autoconf
./configure && ./makeit
For Bullet, there should be a bullet.pc file installed on your system which you can use with the autocong macro PKG_CHECK_MODULES, the same way OGRE and OIS are included:
# in configure.ac
PKG_CHECK_MODULES(BULLET, [bullet])
# in Makefile.am
OgreApp_CXXFLAGS= $(OGRE_CFLAGS) $(OIS_CFLAGS) $(BULLET_CFLAGS)
OgreApp_LDADD= $(OGRE_LIBS) $(OIS_LIBS) $(BULLET_LIBS)
If you add more unconditional dependencies, you might want to simplify both files by grouping them like this:
# in configure.ac
PKG_CHECK_MODULES(DEPENDENCIES, [OGRE >= 1.2 OIS >= 1.0 bullet])
# in Makefile.am
OgreApp_CXXFLAGS= $(DEPENDENCIES_CFLAGS)
OgreApp_LDADD= $(DEPENDENCIES_LIBS)
And as Jack Kelly wrote in the comments, if you have pkg-config >= 0.24 (released in 2010), you don't need to use AC_SUBST after PKG_CHECK_MODULE.
In your Makefile.am:
OgreApp_LIBADD= -llib1 -llib2
Does that help?
Edit: or try appending -llib1 -llib2 to the OgreApp_LDADD=... line, I'm not sure myself.