Click to See Complete Forum and Search --> : gcrypt.h issues


madcompnerd
05-30-2004, 05:49 PM
Hello, little compile issue with a program I'm working on. I'm moderately stumped so I'm posting a request for any info you have on this.
The program includes gcrypt.h:
#include <gcrypt.h> //this is c++ if you haven't realized, and I also tried it with a small c program, same issue, and I have also tried two different computers with different distros (Arch, Debian Unstable)

I can compile fine with gcrypt included, and I can use types defined in that .h file. However, when I attempt to use any functions provided it comes up with an "undefined" function error. The kind one typically receives when he has a template but never defined the function with a body.
libgcrypt does come with some documentation about things to do at compile time, but none of them help. In fact, it's method doesn't seem to work at all for me.
gcc -o foo.o foo.c 'gcrypt-config --cflags --libs'
That gives me an error about not finding gcrypt-config. But when I run gcrypt-config straight from the cli it comes up with output about proper options (so the script is in my path).
My estimate is that g++/gcc is finding /usr/include/gcrypt.h but not finding /usr/lib/libgcrypt.so.* .
Any thoughts or ideas please. Maybe someone has experience with this library.
Thank you.

sploo22
05-30-2004, 05:54 PM
Just checking, but did you make sure to use backquotes instead of single quotes around the gcrypt-config part?

madcompnerd
05-30-2004, 06:07 PM
Oh cool, that gets it to compile.
I should learn to see the different between single quotes and back quotes.....

bwkaz
05-30-2004, 06:15 PM
Originally posted by madcompnerd
gcc -o foo.o foo.c 'gcrypt-config --cflags --libs'

That gives me an error about not finding gcrypt-config. But when I run gcrypt-config straight from the cli it comes up with output about proper options (so the script is in my path). This is expected behavior when you use single quotes instead of backquotes.

With single quotes, gcc interprets the characters between them as a file to compile and/or link. However, you quite obviously don't have a file named 'gcrypt-config --cflags --libs' in your current directory. The "file not found" error is from gcc.

With backquotes, the shell actually runs gcrypt-config, with the passed-in options, and substitutes its output in for the backquoted string. That's what you need. gcrypt-config will print out the options that need to be passed to gcc in order to find the gcrypt header file and link in the gcrypt library.

The initial error message about functions not being found is due to you not linking in the gcrypt library.

madcompnerd
05-30-2004, 09:50 PM
Yea, I've got it to link by feeding it the location of libgcrypt.so at the command line, atm I am trying to figure out how I am supposed to do this with automake though.

bwkaz
05-31-2004, 08:45 AM
Hah! Good luck! ;)

Actually, what you can do is run gcrypt-config from configure.ac (actually, it'll run from configure, but whatever) and store the result in a shell variable (call it whatever you want). Then, AC_SUBST that shell variable into a make variable inside your Makefiles. When you're compiling, use the --cflags part, and when you're linking, use the --libs part (this will require 2 shell+make variables, and 2 invocations of gcrypt-config).

In other words, don't use Automake to do it, use Autoconf.

madcompnerd
05-31-2004, 05:14 PM
Thank you very much, that got it.
It was quite frustrating knowing exactly what I wanted it to do, but having no clue where or how to tell it to do it.
I will have to remember this in the future.