Results 1 to 4 of 4

Thread: 'Undefined reference' to an installed openSSL RSA function

  1. #1
    Join Date
    Oct 2007
    Beans
    21

    'Undefined reference' to an installed openSSL RSA function

    I used apt-get to get libssl-dev. The code is below. When I remove an argument the compiler says that there's too few arguments and when I add an argument the compiler says there's too many arguments, so it seems like there is "some" kind of reference to the correct function. There's some linking going on wrongly perhaps? I'm sure I'm doing something stupid but I can't think of what it could be.

    gcc test.c
    /tmp/ccPG86Ko.o: In function `main':
    test.c.text+0x44): undefined reference to `RSA_generate_key'
    collect2: ld returned 1 exit status


    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <openssl/rsa.h>
    
    int main(int argc, char **argv)
    {
    	RSA* rsa;
    	rsa = RSA_generate_key(1,1, NULL, NULL);
    }
    Last edited by gogetadbl; February 26th, 2009 at 08:53 AM.

  2. #2
    Join Date
    Mar 2006
    Beans
    199

    Re: 'Undefined reference' to an installed openSSL RSA function

    Did you specify the ssl library in the gcc command?

    Code:
    gcc yourfile.c -lssl
    It fails when you remove a parameter because the header file is found ok and the function arguments verified -- but you still must tell it to link the ssl library.

  3. #3
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: 'Undefined reference' to an installed openSSL RSA function

    Many libraries use pkg-config to provide the options needed to compile and link against the library.
    pkg-config --list-all will list all libraries that have added themselves to pkg-config

    Code:
    pkg-config --list-all | grep ssl
    If you find it (in this case libssl or openssl), run
    Code:
    $ pkg-config libssl --cflags --libs
     -lssl
    You can also use the output directly when compiling
    Code:
    $ gcc $(pkg-config libssl --cflags --libs) test.c

  4. #4
    Join Date
    Oct 2007
    Beans
    21

    Re: 'Undefined reference' to an installed openSSL RSA function

    That fixed it, thanks! Glad to know about how to do this in the future for other libraries

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •