Isa*_*iro 1 linux windows autotools shared-libraries static-libraries
在构建既静态和共享库的cmake上的Windows我不得不追加“-static”的静态库名(在Windows中,静态的共享库可以有.LIB扩展名),所以产生的文件名的静态库LIB是lib-static.lib。在任何正在运行的系统上,如何使用automake + libtool(即指示libtool将“ -static ” 附加到生成的静态库文件名之后)来实现它?
在具有的Autotools系统中libtool,如果同时构建静态库和共享库,则它们通常都与同一个libtool库目标相关联,因此它们具有相同的名称,只是扩展名不同。通常这不是问题,因为UNIX风格的约定为此使用了不同的扩展名。实际上,它违反了UNIX约定,以提供具有不同名称词干的静态和共享库。
如果您仍然坚持创建名称不同的静态库和共享库,那么最好的选择就是为它们定义不同的目标。在最坏的情况下,您可以简单地两次构建所有源:
lib_LTLIBRARIES = libfoo.la libfoo-static.la
libfoo_la_SOURCES = source1.c source2.c
# Build *only* a shared library:
libfoo_la_LDFLAGS = -shared
# use the same sources as the shared version:
# note: the underscore in "libfoo_static" is not a mistake
libfoo_static_la_SOURCES = $(libfoo_la_SOURCES)
# Build *only* a static library:
libfoo_static_la_LDFLAGS = -static
Run Code Online (Sandbox Code Playgroud)
但是,如果要避免源代码的多次编译,则应该能够创建一个“便捷库”,从中可以创建两个库:
noinst_LTLIBRARIES = libfoo_funcs.la
lib_LTLIBRARIES = libfoo.la libfoo-static.la
# A convenience library (because noinst)
# Build both static and shared versions
libfoo_funcs_la_SOURCES = source1.c source2.c
# Build *only* a shared library
libfoo_la_LDFLAGS = -shared
# Include the contents of libfoo_funcs.la
libfoo_la_LIBADD = libfoo_funcs.la
# Build *only* a static library
libfoo_static_la_LDFLAGS = -static
# Include the contents of libfoo_funcs.la
libfoo_static_la_LIBADD = libfoo_funcs.la
Run Code Online (Sandbox Code Playgroud)
如果可以将相同的对象首先组合在一起以创建静态库和共享库,那么这仅有助于避免源代码的多次编译。在某些平台上就是这种情况,而在其他平台上则不是。
| 归档时间: |
|
| 查看次数: |
704 次 |
| 最近记录: |