1

I'm trying to make a static link to gcrypt lib in cmake. My cmake looks like this:

cmake_minimum_required(VERSION 3.15)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
set(CMAKE_C_COMPILER /usr/bin/gcc)
set(CMAKE_CXX_COMPILER /usr/bin/g++)
project(testin)

set(CMAKE_CXX_STANDARD 14)

file(GLOB test
        "*.h"
        "*.cpp"
        "*.c"
        "./include/*.h"
        "./src/*.c"
        )

add_executable(testin ${test})

ADD_LIBRARY(libgcrypt STATIC IMPORTED)
SET_TARGET_PROPERTIES(libgcrypt PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libgcrypt.a)
target_link_libraries(testin libgcrypt)

and I've got following errors:

/usr/lib/x86_64-linux-gnu/libgcrypt.a(libgcrypt_la-visibility.o): In function  `gcry_err_make_from_errno':
(.text+0x46): undefined reference to `gpg_err_code_from_errno'
/usr/lib/x86_64-linux-gnu/libgcrypt.a(libgcrypt_la-visibility.o): In function `gcry_error_from_errno':
(.text+0x75): undefined reference to `gpg_err_code_from_errno'
/usr/lib/x86_64-linux-gnu/libgcrypt.a(libgcrypt_la-visibility.o): In function `gcry_strerror':
(.text+0x1): undefined reference to `gpg_strerror'
/usr/lib/x86_64-linux-gnu/libgcrypt.a(libgcrypt_la-visibility.o): In function `gcry_strsource':
(.text+0x11): undefined reference to `gpg_strsource'

..... etc.

I tried to find on Stack what am i doin wrong and i failed to solve this problem. I'm using Clion if it is important. Can someone help me to solve this problem? Thanks in advance for your help.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Coamo
  • 11
  • 2
  • 1
    You need to link to libgpg-error (and friends). There are six different libraries directly needed for libgrcrypt. You need to build all of them. They are listed at the [GnuPG download page](https://www.gnupg.org/download/). You also need to have their dependencies available, like zLib, Bzip and iConv. Also see [Noloader | Build Scripts](https://github.com/noloader/Build-Scripts) on GitHub. It will give you an idea of the dependencies you need to manage. – jww Nov 24 '19 at 14:04
  • 1
    https://stackoverflow.com/q/12573816/5910058 – Jesper Juhl Nov 24 '19 at 14:05
  • I solved it, i had to changed *.a file to *.so file and everything now works. Thanks for your help. – Coamo Nov 24 '19 at 14:42

0 Answers0