libgcrypt-mingw-w64-dev/w static compiling fails

Asked by Julia Rodriguez

I have this package installed, and I'm trying to compile the simplest program possible, which I'v listed below

#include <stdio.h>
#include <gcrypt.h>

int main(int argc, char*argv[]){
  if (!gcry_check_version(GCRYPT_VERSION))
    printf("hello world\nBAD GCRYPT_VERSION\n");
  else
    printf("hello world\nGOOD GCRYPT_VERSION\n");
  return 0;
}

using the compile command:
x86_64-w64-mingw32-gcc -static -o helloworld.exe helloworld.c -lgcrypt

and it gives a long set of errors associated with linking,
/usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/../../../../x86_64-w64-mingw32/lib/libgcrypt.a(libgcrypt_la-visibility.o):(.text+0x2d): undefined reference to `gpg_err_code_from_errno'
/usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/../../../../x86_64-w64-mingw32/lib/libgcrypt.a(libgcrypt_la-visibility.o):(.text+0x52): undefined reference to `gpg_err_code_from_errno'
/usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/../../../../x86_64-w64-mingw32/lib/libgcrypt.a(libgcrypt_la-visibility.o):(.text+0x10): undefined reference to `gpg_strerror'
...

does anyone know how to fix this?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu libgcrypt20 Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Best Manfred Hampl (m-hampl) said :
#1

You probably need to add "-lgpg-error" to you compile command.
This probably requires that the libgpg-error0 or libgpg-error-mingw-w64-dev package is installed.

Revision history for this message
Julia Rodriguez (graphix714) said :
#2

Okay, I have both packages installed, trying to compile with:

x86_64-w64-mingw32-gcc -static -o helloworld.exe helloworld.c -lgpg-error -lgcrypt

and it gives what look to be the same set of errors associated with linking,

/usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/../../../../x86_64-w64-mingw32/lib/libgcrypt.a(libgcrypt_la-visibility.o):(.text+0x2d): undefined reference to `gpg_err_code_from_errno'
/usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/../../../../x86_64-w64-mingw32/lib/libgcrypt.a(libgcrypt_la-visibility.o):(.text+0x52): undefined reference to `gpg_err_code_from_errno'
/usr/lib/gcc/x86_64-w64-mingw32/7.3-win32/../../../../x86_64-w64-mingw32/lib/libgcrypt.a(libgcrypt_la-visibility.o):(.text+0x10): undefined reference to `gpg_strerror'
...

Just remembered that the order of the "-l" s might be important, trying one more time:

x86_64-w64-mingw32-gcc -static -o helloworld.exe helloworld.c -lgcrypt -lgpg-error

and compiles without error. test run and:

wine helloworld.exe
hello world
GOOD GCRYPT_VERSION

It works! Thank you helping me solve this!

Revision history for this message
Julia Rodriguez (graphix714) said :
#3

Thanks Manfred Hampl, that solved my question.