0
votes

I am developing a library called libspellcheck, and a program that uses it to check spelling called spellcheck. Here is my directory structure:

libspellcheck
       -> doc
       -> man
       -> libspellcheck (libspellcheck source)
       -> spellcheck (spellcheck source)

I wanted to use a configure script instead of a plain Makefile as I had been using. Everything goes okay until I try compiling spellcheck:

Making all in libspellcheck
make[1]: Entering directory `/home/iandun/libspellcheck-devel/libspellcheck/libspellcheck'
g++ -DHAVE_CONFIG_H -I.     -g -O2 -MT checker.o -MD -MP -MF .deps/checker.Tpo -c -o checker.o checker.cpp
mv -f .deps/checker.Tpo .deps/checker.Po
g++ -DHAVE_CONFIG_H -I.     -g -O2 -MT SpellCorrector.o -MD -MP -MF .deps/SpellCorrector.Tpo -c -o SpellCorrector.o SpellCorrector.cpp
mv -f .deps/SpellCorrector.Tpo .deps/SpellCorrector.Po
rm -f libspellcheck.a
ar cru libspellcheck.a checker.o SpellCorrector.o 
ranlib libspellcheck.a
make[1]: Leaving directory `/home/iandun/libspellcheck-devel/libspellcheck/libspellcheck'
Making all in spellcheck
make[1]: Entering directory `/home/iandun/libspellcheck-devel/libspellcheck/spellcheck'
g++ -DHAVE_CONFIG_H -I.     -g -O2 -MT spellcheck.o -MD -MP -MF .deps/spellcheck.Tpo -c -o spellcheck.o spellcheck.cpp
spellcheck.cpp: In function 'int main(int, char**)':
spellcheck.cpp:111:21: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
  char *dictionary = "/etc/english.dict"; //Default Dictionary
                     ^
spellcheck.cpp:164:14: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   dictionary = "/etc/english.dict";
              ^
mv -f .deps/spellcheck.Tpo .deps/spellcheck.Po
g++ -DHAVE_CONFIG_H -I.     -g -O2 -MT meta.o -MD -MP -MF .deps/meta.Tpo -c -o meta.o meta.cpp
mv -f .deps/meta.Tpo .deps/meta.Po
g++  -g -O2  "../libspellcheck/libspellcheck.a" -o spellcheck spellcheck.o meta.o  
spellcheck.o: In function `correctMisspelled(std::string, std::string)':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:29: undefined reference to `correctSpelling(std::string, std::string)'
spellcheck.o: In function `doFileCheck(char*, char*, char*, spelling)':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:61: undefined reference to `check_spelling_file(char*, char*, std::string)'
spellcheck.o: In function `main':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:193: undefined reference to `add_word(char*, char*)'
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/spellcheck.cpp:224: undefined reference to `check_spelling_string(char*, std::string, std::string)'
meta.o: In function `do_about_msg()':
/home/iandun/libspellcheck-devel/libspellcheck/spellcheck/meta.cpp:29: undefined reference to `lib_version()'
collect2: error: ld returned 1 exit status
make[1]: *** [spellcheck] Error 1
make[1]: Leaving directory `/home/iandun/libspellcheck-devel/libspellcheck/spellcheck'
make: *** [all-recursive] Error 1

I put a reference to libspellcheck.a in my Makefile.am file in the spellcheck directory:

CFLAGS = -m32 -Wall 
LDFLAGS = "../libspellcheck/libspellcheck.a"

bin_PROGRAMS = spellcheck
spellcheck_SOURCES = spellcheck.cpp meta.cpp 

And also changed my references to the spellcheck header file:

#include "../libspellcheck/spellcheck.h"

Here is my Makefile.am in the libspellcheck folder:

CFLAGS = -m32 -Wall
LDFLAGS = 

lib_LIBRARIES = libspellcheck.a
libspellcheck_a_SOURCES = checker.cpp SpellCorrector.cpp 

include_HEADERS = spellcheck.h SpellCorrector.h

Here is my Makefile.am in the main folder:

AUTOMAKE_OPTIONS = foreign
SUBDIRS = libspellcheck spellcheck man

And my configure.ac:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT(libspellcheck, 1.25, [email protected])
AC_OUTPUT(Makefile libspellcheck/Makefile spellcheck/Makefile man/Makefile)
AC_CONFIG_SRCDIR([])
AC_CONFIG_HEADERS([])
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

What am I doing wrong?

1

1 Answers

2
votes
CFLAGS = -m32 -Wall 
LDFLAGS = "../libspellcheck/libspellcheck.a"

First, these are user flags. Use the AM_* forms instead.

Second, LDFLAGS is for flags. It is put near the start of the command line. But, for linking, order matters, so you want to use LDADD instead. There are a few ways to do this but perhaps the best is to use the per-target variable:

spellcheck_LDADD = ../libspellcheck/libspellcheck.a

You don't need those quotes.