无法完全将 link cpp 项目编译为静态库
Cannot totally compile and link cpp project as a static library
我已遵循此 link 并调整其步骤以使其适用于我的项目。
我的目标是创建一个 libfile.a
作为静态库分发。项目树如下:
project
|
+-src
+- <some cpp and hpp files>
|
+ containers
|
+- <other cpp and hpp files>
我轻松创建了 configure.ac
文件和 Makefile.am
。树结构改成这样:
project
|
+- configure.ac
+- Makefile.am
+-src
+- <some cpp and hpp files>
+ Makefile.am
|
+ containers
|
+- <other cpp and hpp files>
现在,当我去的时候:(*)
aclocal; autoreconf --install; autoconf; ./configure
make
.o files
是为 src
中包含的所有 .*pp files
生成的,但是当它开始生成 src/containers
中的那些目标时它失败了。所以 Makefile
没有正确生成。我究竟做错了什么?有人可以帮助我吗?
PS这里涉及到文件:
# --- configure.ac ---
AC_PREREQ([2.68])
AC_INIT([filea], [1.0], [dev@host.net])
AM_INIT_AUTOMAKE([filea], [1.0])
AC_CONFIG_SRCDIR([src/HashFunctions.cpp])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CXX
AC_PROG_RANLIB
AC_CHECK_HEADERS([stddef.h stdint.h string.h])
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([memset])
AC_OUTPUT([Makefile src/Makefile])
# --- Makefile.am ---
AUTOMAKE_OPTIONS = foreign
SUBDIRS = src
# --- src/Makefile.am ---
lib_LIBRARIES = libfile.a
libfile_a_SOURCES = \
ConfigLib.hpp \
ConfigLib.cpp \
HashFunctions.cpp \
HashFunctions.hpp \
Logger.hpp \
Logger.cpp \
Queue.hpp
libfile_a_SOURCES += \
containers/SafeContainer.cpp \
containers/SafeInterger.cpp \
containers/SafeMap.cpp
编辑 1
根据 Brett Hale 的建议,标有 (*)
的命令已被以下命令替换:
autoreconf -fvi
输出:
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'
搭配时:
./configure
make
在子目录中仍然没有找到生成目标的规则。
编辑 2 我切换到非递归方法(感谢 Karel Zak's blog),最后我可以 make
我的库。
我仍然不知道按照典型的 recursive approach
我做错了什么;但是,最后我完成了这项工作,切换到 non-recursive approach
(正如我在 EDIT 2 中所写)。 This article Karel Zak 的博客对我帮助很大!
# -- new configure.ac file --
AC_PREREQ([2.68])
AC_INIT([filea], [1.0], [dev@host.net])
AM_INIT_AUTOMAKE([filea], [1.0])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([src/HashFunctions.cpp])
AM_INIT_AUTOMAKE([filea], [1.0])
LT_INIT
AC_CANONICAL_HOST
AC_PROG_LIBTOOL
AC_PROG_GREP
AC_PROG_EGREP
AC_PROG_CXX
...
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_FUNC_ERROR_AT_LINE
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([memset socket])
AC_OUTPUT([Makefile]) # the makefile is only one!
# In the subdirectory I have created few
# Makemodule.am included in the "main makefile.am"
# --- makefile.am ---
AUTOMAKE_OPTIONS = foreign
lib_LIBRARIES = filea.a
libfilea_a_SOURCES =
include src/Makemodule.am
include src/containers/Makemodule.am # now filea_a_SOURCES is a
# "global variable"
# -- src/Makemodule.am
libfilea_a_SOURCES += \
src/ConfigLib.hpp \
src/ConfigLib.cpp \
src/HashFunctions.cpp \
src/HashFunctions.hpp \
src/Logger.hpp \
src/Logger.cpp \
src/Queue.hpp
# -- src/containers/Makemodule.am
libfile_a_SOURCES += \
src/containers/SafeContainer.cpp \
src/containers/SafeInterger.cpp \
src/containers/SafeMap.cpp
请注意,现在即使 Makemodule.am
文件位于目录树中的不同级别,只要在其中一个模块中键入文件名,就必须在其前面加上其相对路径。此路径相对于 Makefile
位置。
我已遵循此 link 并调整其步骤以使其适用于我的项目。
我的目标是创建一个 libfile.a
作为静态库分发。项目树如下:
project
|
+-src
+- <some cpp and hpp files>
|
+ containers
|
+- <other cpp and hpp files>
我轻松创建了 configure.ac
文件和 Makefile.am
。树结构改成这样:
project
|
+- configure.ac
+- Makefile.am
+-src
+- <some cpp and hpp files>
+ Makefile.am
|
+ containers
|
+- <other cpp and hpp files>
现在,当我去的时候:(*)
aclocal; autoreconf --install; autoconf; ./configure
make
.o files
是为 src
中包含的所有 .*pp files
生成的,但是当它开始生成 src/containers
中的那些目标时它失败了。所以 Makefile
没有正确生成。我究竟做错了什么?有人可以帮助我吗?
PS这里涉及到文件:
# --- configure.ac ---
AC_PREREQ([2.68])
AC_INIT([filea], [1.0], [dev@host.net])
AM_INIT_AUTOMAKE([filea], [1.0])
AC_CONFIG_SRCDIR([src/HashFunctions.cpp])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CXX
AC_PROG_RANLIB
AC_CHECK_HEADERS([stddef.h stdint.h string.h])
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([memset])
AC_OUTPUT([Makefile src/Makefile])
# --- Makefile.am ---
AUTOMAKE_OPTIONS = foreign
SUBDIRS = src
# --- src/Makefile.am ---
lib_LIBRARIES = libfile.a
libfile_a_SOURCES = \
ConfigLib.hpp \
ConfigLib.cpp \
HashFunctions.cpp \
HashFunctions.hpp \
Logger.hpp \
Logger.cpp \
Queue.hpp
libfile_a_SOURCES += \
containers/SafeContainer.cpp \
containers/SafeInterger.cpp \
containers/SafeMap.cpp
编辑 1
根据 Brett Hale 的建议,标有 (*)
的命令已被以下命令替换:
autoreconf -fvi
输出:
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'
搭配时:
./configure
make
在子目录中仍然没有找到生成目标的规则。
编辑 2 我切换到非递归方法(感谢 Karel Zak's blog),最后我可以 make
我的库。
我仍然不知道按照典型的 recursive approach
我做错了什么;但是,最后我完成了这项工作,切换到 non-recursive approach
(正如我在 EDIT 2 中所写)。 This article Karel Zak 的博客对我帮助很大!
# -- new configure.ac file --
AC_PREREQ([2.68])
AC_INIT([filea], [1.0], [dev@host.net])
AM_INIT_AUTOMAKE([filea], [1.0])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR([src/HashFunctions.cpp])
AM_INIT_AUTOMAKE([filea], [1.0])
LT_INIT
AC_CANONICAL_HOST
AC_PROG_LIBTOOL
AC_PROG_GREP
AC_PROG_EGREP
AC_PROG_CXX
...
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_FUNC_ERROR_AT_LINE
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_CHECK_FUNCS([memset socket])
AC_OUTPUT([Makefile]) # the makefile is only one!
# In the subdirectory I have created few
# Makemodule.am included in the "main makefile.am"
# --- makefile.am ---
AUTOMAKE_OPTIONS = foreign
lib_LIBRARIES = filea.a
libfilea_a_SOURCES =
include src/Makemodule.am
include src/containers/Makemodule.am # now filea_a_SOURCES is a
# "global variable"
# -- src/Makemodule.am
libfilea_a_SOURCES += \
src/ConfigLib.hpp \
src/ConfigLib.cpp \
src/HashFunctions.cpp \
src/HashFunctions.hpp \
src/Logger.hpp \
src/Logger.cpp \
src/Queue.hpp
# -- src/containers/Makemodule.am
libfile_a_SOURCES += \
src/containers/SafeContainer.cpp \
src/containers/SafeInterger.cpp \
src/containers/SafeMap.cpp
请注意,现在即使 Makemodule.am
文件位于目录树中的不同级别,只要在其中一个模块中键入文件名,就必须在其前面加上其相对路径。此路径相对于 Makefile
位置。