Re: Can't make dll out of a static convenience library: This system cannot link to static lib

2020-07-10 Thread Bob Friesenhahn

On Sat, 4 Jul 2020, basini...@gmail.com wrote:


Hi. I'm trying to build mingw-w64-gnutls 3.6.12 on Archlinux. At some point it 
wants to make a C++ dll out of a C convenience static library and a C++ object 
file, but libtool omits the static library and link fails with undefined 
reference.
I don't understand why libtool omits the static library, because if I call g++ 
directly the dll is created just fine. I had to manually add `-lssp` to the 
command line, but I'm not sure if that's the cause.


Libtool assumes that static libraries do not contain objects which are 
built appropriately for use in shared libraries or DLLs.  Quite often 
objects need to be built in special ways (e.g -fPIC, 
dllexport/dllimport declarations) in order to work in shared 
libraries.


Bob
--
Bob Friesenhahn
bfrie...@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,http://www.GraphicsMagick.org/
Public Key, http://www.simplesystems.org/users/bfriesen/public-key.txt



Can't make dll out of a static convenience library: This system cannot link to static lib

2020-07-04 Thread basinilya
Hi. I'm trying to build mingw-w64-gnutls 3.6.12 on Archlinux. At some point it 
wants to make a C++ dll out of a C convenience static library and a C++ object 
file, but libtool omits the static library and link fails with undefined 
reference.
I don't understand why libtool omits the static library, because if I call g++ 
directly the dll is created just fine. I had to manually add `-lssp` to the 
command line, but I'm not sure if that's the cause.

Failure:

[il@arch lib]$ make V=1
...
make[2]: Entering directory 
'/home/il/.cache/pikaur/build/mingw-w64-gnutls/src/gnutls-3.6.12/build-i686-w64-mingw32/lib'
/bin/sh ../libtool  --tag=CXX   --mode=link i686-w64-mingw32-g++ 
-I../../lib/includes -I./includes -D_FORTIFY_SOURCE=2 -O2 -pipe -fno-plt 
-fexceptions --param=ssp-buffer-size=4  -no-undefined -version-info 29:0:1 
-Wl,-O1,--sort-common,--as-needed -fstack-protector  -o libgnutlsxx.la -rpath 
/usr/i686-w64-mingw32/lib libgnutlsxx_la-gnutlsxx.lo libgnutls.la

*** Warning: This system cannot link to static lib archive libgnutls.la.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.
libtool: link: rm -fr  .libs/libgnutlsxx.dll.a
libtool: link: i686-w64-mingw32-g++ -shared -nostdlib 
/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/lib/../lib/dllcrt2.o
 /usr/lib/gcc/i686-w64-mingw32/10.1.0/crtbegin.o  
.libs/libgnutlsxx_la-gnutlsxx.o   -L/usr/i686-w64-mingw32/lib 
-L/usr/lib/gcc/i686-w64-mingw32/10.1.0 
-L/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/lib/../lib 
-L/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/lib 
-lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread 
-ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname 
-lmingwex -lmsvcrt /usr/lib/gcc/i686-w64-mingw32/10.1.0/crtend.o  -O2 -Wl,-O1 
-Wl,--sort-common -Wl,--as-needed -fstack-protector   -o 
.libs/libgnutlsxx-28.dll -Wl,--enable-auto-image-base -Xlinker --out-implib 
-Xlinker .libs/libgnutlsxx.dll.a
/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/bin/ld: 
.libs/libgnutlsxx_la-gnutlsxx.o:gnutlsxx.cpp:(.text+0x10): undefined reference 
to `gnutls_deinit'
...
collect2: error: ld returned 1 exit status


Success:

[il@arch lib]$ i686-w64-mingw32-g++ -shared -nostdlib 
/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/lib/../lib/dllcrt2.o
 /usr/lib/gcc/i686-w64-mingw32/10.1.0/crtbegin.o  
.libs/libgnutlsxx_la-gnutlsxx.o \
>   .libs/libgnutls.a  \
  -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread 
-ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname 
-lmingwex -lmsvcrt \
>\
>   -L/usr/i686-w64-mingw32/lib -L/usr/lib/gcc/i686-w64-mingw32/10.1.0 
-L/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/lib/../lib 
-L/usr/lib/gcc/i686-w64-mingw32/10.1.0/../../../../i686-w64-mingw32/lib \
>   -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt 
-lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc 
-lmoldname -lmingwex -lmsvcrt \
>   -lp11-kit -lws2_32 -lunistring -ltasn1 -lnettle -lhogweed -lgmp 
-lcrypt32 \
>   -lssp \
>   /usr/lib/gcc/i686-w64-mingw32/10.1.0/crtend.o  -O2 -Wl,-O1 
-Wl,--sort-common -Wl,--as-needed -fstack-protector   -o 
.libs/libgnutlsxx-28.dll -Wl,--enable-auto-image-base -Xlinker --out-implib 
-Xlinker .libs/libgnutlsxx.dll.a
[il@arch lib]$


[il@arch lib]$ /bin/sh ../libtool --version
libtool (GNU libtool) 2.4.6