How to use OpenSSL with GCC?

前端 未结 5 1752
闹比i
闹比i 2020-11-29 06:47

I\'m trying to use openssl in a gcc program but it isn\'t working.

g++ server.cpp /usr/lib/libssl.a -o server

gives an error message, as d

相关标签:
5条回答
  • 2020-11-29 07:13

    In Eclipse IDE select Your Project property --> c/c++ Build --> Settings gcc c linker(from tools settings)--> add to Library Search Path (-L)

    /usr/lib -lssl -lcrypto

    0 讨论(0)
  • 2020-11-29 07:14

    You or others may find this article developerWorks article helpful.

    • Secure programming with the OpenSSL API
      • https://developer.ibm.com/technologies/linux/tutorials/l-openssl

    It describes most things you need to know to get off the ground with OpenSSL and C/C++. If you find you are following most of the same steps, it might help you see what needs doing.

    Good luck.


    update

    • revised link: https://developer.ibm.com/technologies/linux/tutorials/l-openssl
      • Which has been shuffled around
    • original link: http://www.ibm.com/developerworks/linux/library/l-openssl.html
      • Which now goes to a digest page including the article.

    Note: keeping both links because they be used to find new discoveries.

    0 讨论(0)
  • 2020-11-29 07:20

    The location of the library is not fixed. In my case (Ubuntu 18.04), the .a files are located in /usr/lib/x86_64-linux-gnu/. So here are the complete steps:

    1) install the library,

    sudo apt install libss-dev
    

    2) check the installed files,

    dpkg-query -L libssl-dev
    

    3) change the gcc flags -L(library directory) -l(library name), e.g.,

    gcc XXX.c XXXXX.c -L/usr/lib/x86_64-linux-gnu/ -lcrypto -lssl
    
    0 讨论(0)
  • 2020-11-29 07:23

    On top of the accepted answers, I could not make compile the OpenSSL example for AES-CCM:

    https://github.com/openssl/openssl/blob/master/demos/evp/aesccm.c

    To make it work I needed to add two more things:

    • The Dinamic Linking Library : -ldl
    • The PThread library to use POSIX threading support: -pthread (Adding directly the library with -lpthread is not recommended )
    0 讨论(0)
  • 2020-11-29 07:27

    Without knowing the exact errors you are seeing, it is difficult to provide an exact solution. Here is my best attempt.

    From the information you provided, it sounds as though the linker is failing because it cannot find a reference to the md5 function in libssl.a. I believe this function is actually in libcrypto so you may need to specify this library as well.

    g++ server.cpp -L/usr/lib -lssl -lcrypto -o server

    0 讨论(0)
提交回复
热议问题