[gnutls-help] Using gnutls_malloc()

Vladimir Levijev vladimir.levijev at gmail.com
Mon Mar 23 17:52:32 CET 2015


I can't figure out why gnutls_malloc() is never resolved on Windows
(2008, 32-bit) here. I'm using this code sample:

  #include <gnutls/gnutls.h>
  int main()
      void *p = gnutls_malloc(10);
      return 0;

It compiles perfectly on GNU/Linux (gcc /tmp/hellognutls.c -o
/tmp/hellognutls -Wall -lgnutls, I'm using version 2.12.20 though) but
on Windows (I'm using latest pre-compiled library from gnu.org,
3.3.13) I get linking error:

>cl hellognutls.c -I \gnutls\include /c /Fo"hellognutls.o"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.


>link hellognutls.o \gnutls\lib\libgnutls.dll.a
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

hellognutls.o : error LNK2019: unresolved external symbol
_gnutls_malloc referenced in function _main
hellognutls.exe : fatal error LNK1120: 1 unresolved externals

It won't help even if I add

  extern gnutls_alloc_function gnutls_malloc;

which means gnutls.h is included properly. It only helps if I manually define

  gnutls_alloc_function gnutls_malloc = malloc;

So it seems to me on Windows the line

  gnutls_alloc_function gnutls_malloc = malloc;

from gnutls_mem.c has disappeared or something. Looking at 3.3.13
sources it is in place. Is Windows library compiled in some special
way where *malloc functions are not available? Or what am I doing

Thanks beforehand,


More information about the Gnutls-help mailing list