Automake & Autoconf - 程序无法识别刚刚构建的静态库
Automake & Autoconf - Program Doesn't Recognize Static Library Just Built
我正在开发一个名为libspellcheck的库,以及一个使用它来检查拼写的程序,该程序名为spellcheck。这是我的目录结构:
libspellcheck
-> doc
-> man
-> libspellcheck (libspellcheck source)
-> spellcheck (spellcheck source)
我想使用配置脚本,而不是我一直使用的普通Makefile。一切都很顺利,直到我尝试编译拼写检查:
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
我在拼写检查目录下的Makefile.am文件中引用了libspellcheck.a:
CFLAGS = -m32 -Wall
LDFLAGS = "../libspellcheck/libspellcheck.a"
bin_PROGRAMS = spellcheck
spellcheck_SOURCES = spellcheck.cpp meta.cpp
还更改了我对拼写检查头文件的引用:
#include "../libspellcheck/spellcheck.h"
这是我在libspellcheck文件夹中的Makefile.am:
CFLAGS = -m32 -Wall
LDFLAGS =
lib_LIBRARIES = libspellcheck.a
libspellcheck_a_SOURCES = checker.cpp SpellCorrector.cpp
include_HEADERS = spellcheck.h SpellCorrector.h
这是我的Makefile.am在主文件夹中:
AUTOMAKE_OPTIONS = foreign
SUBDIRS = libspellcheck spellcheck man
我的配置.ac:
# -*- 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([])
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
我做错了什么?
CFLAGS = -m32 -Wall
LDFLAGS = "../libspellcheck/libspellcheck.a"
首先,这些是用户标志。请改用AM_*表格。
第二,LDFLAGS是用于标志的。它被放置在命令行的开头附近。但是,对于链接,顺序很重要,所以您需要使用LDADD。有几种方法可以做到这一点,但也许最好的方法是使用每个目标变量:
拼写检查_LDAD=/libspellcheck/libspellcheck.a
你不需要这些引号。
相关文章:
- 如何在 Linux for Windows 上通过 MinGW 构建静态 ICU 的 Boost
- 使用 openssl 构建静态二进制文件的正确方法是什么?
- '在使用安卓 NDK r10e 构建静态库时无效使用'auto'
- CMake 构建静态可执行文件
- 如何使用捆绑依赖项-CMAKE构建静态库
- 用C 元编程构建静态字符串
- 构建静态QT时未解决的外部
- 如何链接和调用安卓工作室预构建静态原生库的函数
- 如何避免在 Bazel 中构建C++静态库
- 如何找到使用Xcode构建静态库时自我定义的名称空间
- 如何从可从C++代码调用的 Ada 源代码构建静态库?
- 如何使用Android Studio和Gradle在Android上使用NDK从C 构建静态库
- 使用Clang构建C++静态库时的奇怪行为
- 在使用自动工具构建静态/共享库时,如何避免双重编译
- 如何在WAF中构建静态库
- 在 Windows 上为 glut 3.7 构建静态库
- 如何使用Qt构建静态库和可执行文件
- 使用cygwin为windows构建静态库
- GNU Automake - 构建静态链接到其依赖项的动态库
- c++如何构建静态私有成员的getter