Openssl compile error

31,180

Solution 1

Put the libraries after the source file:

gcc -o openssl openssl.c -lssl -lcrypto

See: http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html

Solution 2

put the file name before -l option

Share:
31,180
Harikrishnan
Author by

Harikrishnan

Wellversed in: PySpark iOS Application Development Android Application Development Windows UWP Development Electron Angular Hadoop Ecosystem AWS Programming Languages: Java Kotlin Python Javascript Swift Objective-C Love to: Read Travel(I am the one driving/Riding) Movies/Series Code Sleep Interests: Cars Motorcycles Gadgets New Technologies PS : Also loves to keep the above list ever expanding!!!

Updated on September 15, 2020

Comments

  • Harikrishnan
    Harikrishnan over 3 years

    I have included the following header files in a C code using openssl libraries.

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <time.h>
    #ifdef __VMS
    #include <in.h>
    #include <inet.h>
    #else
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #endif
    #include <openssl/crypto.h>
    #include <openssl/ssl.h>
    #include <openssl/err.h>
    

    Then I compiled the program using gcc -o openssl -lssl -lcrypt openssl.c In my office this code compiled and run fine but in my house system(both are linux- debian 6 in office and Ubuntu 12.04 at home), it gave the following error:

    /tmp/ccZcmLk4.o: In function `main':
    server.c:(.text+0x3d): undefined reference to `SSL_library_init'
    server.c:(.text+0x42): undefined reference to `SSL_load_error_strings'
    server.c:(.text+0x47): undefined reference to `SSLv3_method'
    server.c:(.text+0x57): undefined reference to `SSL_CTX_new'
    server.c:(.text+0x6f): undefined reference to `ERR_print_errors_fp'
    server.c:(.text+0x97): undefined reference to `SSL_CTX_use_certificate_file'
    server.c:(.text+0xa8): undefined reference to `ERR_print_errors_fp'
    server.c:(.text+0xd0): undefined reference to `SSL_CTX_use_PrivateKey_file'
    server.c:(.text+0xe1): undefined reference to `ERR_print_errors_fp'
    server.c:(.text+0xf9): undefined reference to `SSL_CTX_check_private_key'
    server.c:(.text+0x154): undefined reference to `SSL_CTX_load_verify_locations'
    server.c:(.text+0x165): undefined reference to `ERR_print_errors_fp'
    server.c:(.text+0x18d): undefined reference to `SSL_CTX_set_verify'
    server.c:(.text+0x1a1): undefined reference to `SSL_CTX_set_verify_depth'
    server.c:(.text+0x397): undefined reference to `SSL_new'
    server.c:(.text+0x3c2): undefined reference to `SSL_set_fd'
    server.c:(.text+0x3ce): undefined reference to `SSL_accept'
    server.c:(.text+0x3e6): undefined reference to `ERR_print_errors_fp'
    server.c:(.text+0x3fe): undefined reference to `SSL_get_current_cipher'
    server.c:(.text+0x406): undefined reference to `SSL_CIPHER_get_name'
    server.c:(.text+0x42e): undefined reference to `SSL_get_peer_certificate'
    server.c:(.text+0x455): undefined reference to `X509_get_subject_name'
    server.c:(.text+0x46d): undefined reference to `X509_NAME_oneline'
    server.c:(.text+0x4b1): undefined reference to `X509_get_issuer_name'
    server.c:(.text+0x4c9): undefined reference to `X509_NAME_oneline'
    server.c:(.text+0x50d): undefined reference to `X509_free'
    server.c:(.text+0x593): undefined reference to `SSL_write'
    server.c:(.text+0x5ab): undefined reference to `ERR_print_errors_fp'
    server.c:(.text+0x5d3): undefined reference to `SSL_read'
    server.c:(.text+0x5eb): undefined reference to `ERR_print_errors_fp'
    collect2: ld returned 1 exit status
    

    I understand that this is due to the absence of certain libraries in my home PC. But can anyone tell me which libraries I need to install for this? Thanks in advance.

  • Harikrishnan
    Harikrishnan almost 12 years
    Well, that worked. But it returned a warning which i didn't get at office. server.c: In function ‘main’: server.c:55:7: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default] I am afraid I will have to paste the entire code to show you where the problem is. But it was certainly not at office.
  • HonkyTonk
    HonkyTonk almost 12 years
    @Hari You are using different compiler versions, yes? Either adjust the flags during compilation to harmonize the warnings or get used to different compiler output. Preferably you should use the same compiler version on both locations.
  • Orion Lawlor
    Orion Lawlor over 7 years
    I had to do -lssl -lcrypto (note the 'o'!) to avoid a mysterious undefined reference to symbol PEM_read_bio_DHparams