Conditionally disable shared library build

▼魔方 西西 提交于 2019-12-11 02:55:53

问题


I’ve written a C library that builds using Libtool, and I’d like to only build static libraries on Cygwin. To that end, I placed

if test "$target_os" = "cygwin"; then
    AC_DISABLE_SHARED
fi

in my configure.ac.

This does indeed disable building shared libraries on Cygwin; however, it also disables building them everywhere else. I assume this is because expanding AC_DISABLE_SHARED causes some unfortunate side effects.

How can I use Libtool to avoid building shared libraries on Cygwin while still building them on other platforms?


回答1:


I'm not sure $target_os is what you want. $host_os is the name for the system the code will run on. The 'target' triple is rarely used outside of building compilers / toolchains.

Even though the configure script might still say yes / enabled for shared libraries, you can override the result by setting the enable_shared|static variables.

AC_CANONICAL_HOST
...
LT_INIT

case $host_os in
  cygwin*)
    AC_MSG_RESULT([explicitly disabled shared libraries for $host])
    enable_shared=no; enable_static=yes ;;
esac

These variables aren't documented, so it's technically a hack - but it's basically behaving like any other AC_ARG_ENABLE option. Your original idea might still work if it appears before LT_INIT, but this approach overrides any configure options.



来源:https://stackoverflow.com/questions/21420574/conditionally-disable-shared-library-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!