libtool: error: can't build x86_64-w64-mingw32 shared library unless -no-undefined is specified

1.1k views Asked by At

I am trying to build and install the OpenFst library on windows10 using MINGW64 with Msys but i got the following error during the building with make. I first used this command:

 ./configure --enable-grm --enable-far --enable-ngram-fsts MAKE="mingw32-make"

some of the checking results from this command generates no:

checking whether we are cross compiling... no
checking for sysroot... no
checking for a working dd... ./configure: line 7016: cmp: command not found
./configure: line 7016: cmp: command not found
checking for mt... no
checking if : is a manifest tool... no
checking for unistd.h... no
checking if gcc supports -fno-rtti -fno-exceptions... ./configure: line 8930: diff: command `not found`
checking whether to build static libraries... no

The other checking results are ok and yes. Then I used the make command:

mingw32-make

it works for some files then terminated by that error:

libtool:   error: can't build x86_64-w64-mingw32 shared library unless -no-undefined is 
specified

It is my first time to build with MinGW. So, I do not know what the error means and if the resulting "no" checking from the configuration responsible for it.

1

There are 1 answers

2
Brecht Sanders On BEST ANSWER

This is normal.

MinGW does not allow building shared libraries (DLLs) when there are still unresolved symbols, because on Windows each symbol referenced from a DLL must point to something that exists. On other platforms this is not always required.

So you should pass to -Wl,-no-undefined to gcc when linking.

For projects using autoconf's configure this is normally already done if it was a recent enough version of autoconf. Otherwise you may need to add LDFLAGS="-Wl,-no-undefined" to the configure line. If that doesn't help you can try to change it in the libtool file generated by configure.

So specicially you can try this in MSYS/MSYS2 shell:

./configure LDFLAGS="-Wl,-no-undefined"

and if that doesn't work you can also try this (after the configure command and before running make):

sed -i.bak -e "s/\(allow_undefined=\)yes/\1no/" libtool

Other build tools like cmake, meson or scons already know how to build Windows DLLs and need no special treatment.