Undefined reference to __imp_gnutls_free error with static build on MinGW
Description of problem:
Undefined reference to __imp_gnutls_free error when linking with static build of GnuTLS.
Version of gnutls used:
3.6.15
Distributor of gnutls (e.g., Ubuntu, Fedora, RHEL)
gnutls.org
How reproducible:
Windows 10
Download MSYS2 from https://www.msys2.org/
Install MSYS2
Upgrade and install development packages
$ pacman -Syu
$ pacman -S autoconf automake libtool make mingw-w64-x86_64-toolchain git
$ mkdir ~/prefix`
$ export set PREFIX=/home/user/prefix
$ export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
$ cd ~
$ curl -O https://gmplib.org/download/gmp/gmp-6.2.0.tar.xz
$ tar xf gmp-6.2.0.tar.xz
$ cd gmp-6.2.0
$ ./configure --build=x86_64-w64-mingw32 --prefix=$PREFIX --enable-static --disable-shared --enable-fat
$ make install
$ cd ~
$ curl -O https://ftp.gnu.org/gnu/nettle/nettle-3.5.1.tar.gz
$ tar xf nettle-3.5.1.tar.gz
$ cd nettle-3.5.1
$ ./configure --build=x86_64-w64-mingw32 --prefix=$PREFIX --enable-static --disable-shared --enable-fat
$ make install
$ cd ~
$ curl -O ftp://ftp.gnutls.org/gcrypt/gnutls/v3.6/gnutls-3.6.15.tar.xz
$ tar xf gnutls-3.6.15.tar.xz
$ cd gnutls-3.6.15
$ ./configure --prefix=$PREFIX --enable-static --disable-shared --build=x86_64-w64-mingw32 --with-included-libtasn1 --disable-doc --disable-guile --without-p11-kit --enable-local-libopts --disable-nls --with-included-unistring
$ make && make install
$ cd ~
$ g++ -o bug -DWIN32 -D_WIN32 -I $PREFIX/include bug.cpp -L$PREFIX/lib -lgnutls -lhogweed -lnettle -lgmp -ladvapi32 -lws2_32 -lcrypt32 -lncrypt
bug.cpp
#include <gnutls/gnutls.h>
int main()
{
gnutls_init(0, 0);
gnutls_free(0);
}
Actual results:
D:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\msys64\tmp\ccKcC8Qw.o:bug.cpp:(.text+0x1f): undefined reference to `__imp_gnutls_free'
collect2.exe: error: ld returned 1 exit status
Expected results:
No link error