Compiling and linking OpenSSL on Ubuntu vs OSX

前端 未结 2 725
天涯浪人
天涯浪人 2020-12-21 00:14

Attempt 1, Vanilla Link to Library

I\'m trying to use a patched version of OpenSSL (so DTLS is easier to use). OpenSSL is in

/usr/lo         


        
相关标签:
2条回答
  • 2020-12-21 00:47

    The problem with the header file not being found seems to be you mixing up your options. -L adds a path to the linker library search paths, while -I adds a directory to the preprocessor header file search path. Change the -L to -I to solve that problem:

    $ gcc -I/usr/local/openssl-1.0.1c/include server.c -o server.o
    

    Now the linker problem is because you erroneously use the -L option to tell the linker to look for libraries in the include path. You need to change that path to the directory where the libraries are, usually a lib subdirectory. Also, the linker wants libraries in reverse order of their dependencies, so place the libraries you want to link with last on the command line:

    $ gcc -I/usr/local/openssl-1.0.1c/include server.c -o server.o \
        -L/usr/local/openssl-1.0.1c/lib -lssl -lcrypto
    
    0 讨论(0)
  • 2020-12-21 01:03

    Your compilation command appears to work on OSX but is actually compiling and linking with the system-provided OpenSSL rather than the version you wanted. It fails outright on Ubuntu because you don't have the headers and development library links for the system OpenSSL installed.

    This is because you have the search path options mixed up, and you need two of them. To tell GCC where headers are you use -I. To tell it where object-code libraries are you use -L. The compilation command you need, ON BOTH SYSTEMS, is something like this:

    $ gcc -I /usr/local/openssl-1.0.1c/include -L /usr/local/openssl-1.0.1c/lib \
          -o server server.c -lssl -lcrypto
    
    0 讨论(0)
提交回复
热议问题