将OpenSSL库链接到一个程序 [英] Linking OpenSSL libraries to a program

查看:181
本文介绍了将OpenSSL库链接到一个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从源代码构建了OpenSSL(一个故意的旧版本;使用 ./ config&&make& make test 构建),并且倾向于使用我没有做 make install 来连接我的程序。



失败的命令是:

  gcc -Wall -Wextra -Werror -static -Lopenssl / openssl-0.9.8k / -lssl -lcrypto 
-Iopenssl /openssl-0.9.8k/include -o myApp source1.o source2.o common.o`

我收到了一系列类似于以下错误:

  common.c :(。text + 0x1ea):未定义引用`SSL_write '

这让我觉得我的OpenSSL有点时髦。如果我在命令中省略 -Lopenssl / openssl-0.9.8k / ,错误将变为无法:

  / usr / bin / ld:找不到-lssl 
/ usr / bin / ld:找不到-lcrypto

我是否错误地编译OpenSSL?或者我该如何最好地解决这个问题?

解决方案

傻傻的Linux主义再次罢工!显然,我需要改变我的命令,使得 -L -l <​​/ code>这些东西在最后是 like(尽管 man gcc 似乎表明):

gcc -Wall -Wextra -Werror -static -o myApp source1.o source2.o common.o -Lopenssl / openssl-0.9.8k / -lssl -lcrypto -Iopenssl / openssl-0.9.8k / include

I have built OpenSSL from source (an intentionally old version; built with ./config && make && make test) and would prefer to use what I have built without doing make install to link against my program.

The command that's failing is:

gcc -Wall -Wextra -Werror -static -Lopenssl/openssl-0.9.8k/ -lssl -lcrypto 
-Iopenssl/openssl-0.9.8k/include -o myApp source1.o source2.o common.o`

And I receive a series of errors similar to:

common.c:(.text+0x1ea): undefined reference to `SSL_write'

This makes me think there's something funky with my OpenSSL. If I omit -Lopenssl/openssl-0.9.8k/ from my command, the error changes to being unable to:

/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto

Am I compiling OpenSSL incorrectly? Or how should I best resolve this?

解决方案

Silly "Linux-isms" strike again! Apparently, I need to change my command such that the -L and -l stuff is at the end like (despite what man gcc seems to indicate):

gcc -Wall -Wextra -Werror -static -o myApp source1.o source2.o common.o -Lopenssl/openssl-0.9.8k/ -lssl -lcrypto -Iopenssl/openssl-0.9.8k/include

这篇关于将OpenSSL库链接到一个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆