Re: PLEASE HELP - How do I include OpenSSL in my code?



On 2006-05-12, cpptutor2000@xxxxxxxxx <cpptutor2000@xxxxxxxxx> wrote:
Could some C guru please help me? I have a simple piece of code as:

#include <stdio.h>
#include <stdlib.h>
#include <openssl/rand.h>

int main(){
unsigned char temp[4];

RAND_bytes(temp, 4);
return 0;
}

If I type: whereis openssl
I get: openssl: /usr/bin/openssl /usr/include/openssl
/usr/share/man/man1/openssl.1ssl.gz

I compile this as:
gcc -g -o test test.c -I/usr/include/openssl -L/usr/bin/openssl

I get a linker error message as :
/tmp/cc4tQEqd.o(.text+0x1af0): In function `main':
/home/ecelrc/students/abanerj/cpp/test.c:6: undefined reference to
`RAND_bytes'

Could someone please point out what I am doing wrong? Any help would be
greatly
appreciated.

You need -l.

-L tells gcc where to look for libraries, -l tells it what libraries to
look in for symbols.

-lxxx means "look for a library called libxxx.a in the usual places".
You add places to "the usual places", if necessary, with -L.

The library you want is libssl.a and is quite likely in /usr/lib, where
gcc looks anyway, so -lssl with no -L option will probably do the trick:

$ gcc -g -o test test.c -I/usr/include/openssl -lssl

or also add -L/usr/lib/openssl (or something, depending on where
libssl.a is on your system) if you need it.

(gnu.gcc.help is the right NG for this by the way).
.



Relevant Pages

  • Re: Need your HELP: C in LINUX
    ... As for my editor preference, ... It has a built in function to compile the code using compiler specified in the configuration, but I don't even use that. ... Save your file from the editor, then type in the other window: "gcc file.c" - this is the simplest form of using gcc. ... It depends on what libraries you were using in Windows. ...
    (comp.lang.c)
  • Re: problem of building stardict
    ... checking for gcc... ... checking for C compiler default output file name... ... checking how to recognize dependent libraries... ... checking for gfortran... ...
    (Fedora)
  • problem of building stardict
    ... checking for gcc... ... checking for C compiler default output file name... ... checking how to recognize dependent libraries... ... checking for gfortran... ...
    (Fedora)
  • Re: Nothing happens after freeing kernel memory
    ... different host libraries. ... but sometimes it won't compile through and leave me with some ... It builds binutils and a 'naked' gcc to start with. ... Some build systems also look at the CROSS or CROSS_COMPILE ...
    (comp.os.linux.embedded)
  • Lib X11 compile problem /Xlib.h:3573: error: syntax error before "_X_SENTINEL"
    ... checking for gcc... ... checking for C compiler default output file name... ... checking how to recognise dependent libraries... ...
    (comp.os.linux.x)