Porting to OS/2: Case #3 libtool and DLLs

libtool is a part of autotools to create shared libraries in an unified way on various platforms. Unfortunately, however, libtool lacks OS/2 support. So patches for this are provided separately. To use this patched libtool, you should regenerate your build system with autoreconf. Then libtool works well on OS/2 as expected.

By the way, this is not enough. Unlike Unix-like systems, OS/2 does not allow to create DLLs which have undefined symbols. This is possible to static libs. But DLLs have to have all the symbols like the executables. For this, libtool requires some flags. That is, -no-undefined. Without this flag, libtool complains about that, and creates static libs instead of DLLs. For examples, if removing -no-undefined from linker flags of FLAC, the following message is printed.

1
2
  CCLD     libFLAC.la
libtool: link: warning: undefined symbols not allowed in i386-pc-os2-emx shared


What is how to add -no-undefined flag ?

There are two ways. First, add -no-undefined to LDFLAGS before calling configure.

1
2
3
4
5
extproc sh

export LDFLAGS=-no-undefined

./configure "$@"


However, this has a problem. When testing in configure, libtool is not used. By the way , -no-undefined is a libtool flag. So gcc does not understand it. Some verions of gcc such as gcc335 shipped with kLIBC treat it as an warning and ignore it. and another verions of gcc such as gcc4.x by Paul Smedley treat it as an error and configure stops. Because gcc4.x checks arguments more strictly. Therefore this way works with gcc335 only.

Second, add -no-undefined to LDFLAGS in configure.ac. Like FLAC, it is possible that codes for -no-undefined already exist. Then, add -no-undefined by conventions. Here are the real codes in FLAC.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
case "$host" in
    *-*-cygwin|*mingw*)
        # define this variable for enabling strict exports with libtool; for now, it's supported by Win32 and OS/2
        LT_NO_UNDEFINED="-no-undefined"
        CPPFLAGS="-D__MSVCRT_VERSION__=0x0601 $CPPFLAGS"
        os_is_windows=yes
        ;;
    *emx*)
        LT_NO_UNDEFINED="-no-undefined"
        ;;
    *)
        LT_NO_UNDEFINED=
        ;;
esac


Or, just add it to LDFLAGS like this.

1
2
3
4
5
case "$host" in
    *-*-os2*)
        LDFLAGS="$LDFLAGS -no-undefined"
        ;;
esac


Preserve previous LDFLAGS, else the previous LDFLAGS will lose.

This may be written like this, again.

1
2
AS_CASE([$host],
  [*-*-os2*], [LDFLAGS="$LDFLAGS -no-undefined"])


Remember that codes to add -no-undefined to LDFLAGS should be placed after configure test. Otherwise, the problem explained in first way occurs. It seems to be proper before AC_OUTPUT().

// ----- 2014/12/15
$host and $host_os requires AC_CANONICAL_HOST. If AC_CANONICAL_HOST is not called in configure.ac, then you must call AC_CANONICAL_HOST before using $host and $host_os like this,

1
2
3
AC_CANONICAL_HOST
AS_CASE([$host],
        [*-*-os2*], [LDFLAGS="$LDFLAGS -no-undefined"])
 

// -----

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷