On 25/04/2010 12:39, Ralf Wildenhues wrote:
* Kārlis Repsons wrote on Sun, Apr 25, 2010 at 12:07:44PM CEST:
On Sunday 25 April 2010 08:22:12 Ralf Wildenhues wrote:
You can use libtool for portable creation of shared libraries.
http://www.gnu.org/software/libtool is the place to go to,
and [email protected] is the list to ask questions on.
Thanks, I'll read that, just it's somewhat confusing how to start,
when there are three programs to deal with.
Most trivial example, untested:

cat>configure.ac<<\END
AC_INIT([my-package], [1.0], [my-email-address])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
LT_INIT([win32-dll])
Does this affect the fact that I might also be targeting Unix like systems, as well as WinSDK?
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
END

cat>Makefile.am<<\END
lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = foo.c
libfoo_la_LDFLAGS = -no-undefined
bin_PROGRAMS = bar
bar_SOURCES = bar.c
bar_LDADD = libfoo.la
END

mkdir m4
touch foo.c bar.c

libtoolize -c
autoreconf -vi

./configure --host=i586-mingw32msvc  # the prefix of my cross compiler
make
make install


In addition, I'd add to my configure.ac scripts (libtool 2.2.6)

LT_LANG([Windows Resource])
AM_CONDITIONAL([HAVE_WINDRES], [test x$ac_cv_prog_ac_ct_RC != x])

And if you want your libraries to be usable by most other programming languages on Win32 (Win64 doesn't have this problem), I also add stdcall in configure.ac:

SHLIB_VERSION_ARG=""
if test x$ac_cv_c_compiler_gnu = xyes; then
   case "$host_os" in
      mingw* | cygwin*)
         SHLIB_VERSION_ARG="-Wl,--add-stdcall-alias"
# You could also use "-Wl,--kill-at" and you'd only one export. But
         # we use --add-stdcall-alias to make linking easier.
                 ;;
          *)
                 ;;
   esac
fi
AC_SUBST(SHLIB_VERSION_ARG)

and in Makefile.am:

libfoo_la_LDFLAGS = -no-undefined @SHLIB_VERSION_ARG@

Then if you want to include resources in your DLL (to show a version number for example), put the following in Makefile.am

.rc.lo:
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) $< -o $@

I actually create a rsrc.rc.in file that gets converted to an rsrc.rc file by configure that contains a bunch of internal information (e.g. debug, etc.) so I can audit my dlls better later.

You might also need to check for __MSVCRT__ to test if you're compiling for Windows or Posix (e.g. checking for Windows.h is unreliable as your users might use a native Cygwin compiler).

Cheers,
Jason.


_______________________________________________
Autoconf mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/autoconf

Reply via email to