如何在Ubuntu上针对OpenSSL 1.0.0安装和构建? [英] How do I install and build against OpenSSL 1.0.0 on Ubuntu?

查看:3039
本文介绍了如何在Ubuntu上针对OpenSSL 1.0.0安装和构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以将此问题视为后续问题,如何在Ubuntu上安装OpenSSL C ++库?



我试图在Ubuntu 10.04 LTS上构建需要OpenSSL 1.0.0的代码。



Ubuntu 10.04 LTS附带OpenSSL 0.9.8k:

  $ openssl version 
OpenSSL 0.9.8k 2009年3月25日

> sudo apt-get install libssl-dev 并建立,运行ldd确认我已在0.9.8链接:

 code> $ ldd foo 
...
libssl.so.0.9.8 => /lib/i686/cmov/libssl.so.0.9.8(0x00110000)
...
libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8(0x002b0000)
...

如何安装OpenSSL 1.0.0和1.0.0开发包?



更新:我正在撰写此更新阅读 SB 的答案(但在尝试之前),因为很清楚,我需要解释下载和安装OpenSSL 1.0.0不起作用:



成功执行以下操作(在INSTALL文件中推荐):

  $ ./config 
$ make
$ make test
$ make install

...我还是得到:

  OpenSSL 0.9.8k 25 Mar 2009 

...和:

  $ sudo apt-get install libssl-dev 
读取软件包列表...完成
构建依赖关系树
读取状态信息...完成
libssl-dev已经是最新版本。
以下软件包已自动安装并不再需要:
linux-headers-2.6.32-21 linux-headers-2.6.32-21-generic
使用'apt-get autoremove 删除它们。
0升级,0新安装,0删除和0未升级。

...(为了确保)重建我的代码后,ldd仍然返回相同的东西

更新#2 :我添加了-I / usr / local / ssl / include和-L / usr / local / ssl / lib选项(由 SB 建议)到我的makefile,但我现在得到一堆未定义的引用编译错误,例如:

  /home/dspitzer/foo/foo.cpp:86:未定义引用`BIO_f_base64'
/home/dspitzer/foo/foo.cpp:86:未定义引用`BIO_new'

/ usr / local / ssl / include /仅包含一个openssl目录(其中包含许多.h文件),所以我也尝试过-I / usr / local / ssl / include / openssl p>

更新#3 :我尝试更改(例如)以下OpenSSL包含:

  #include< openssl / bio.h> 

...至:

  #includeopenssl / bio.h

...

更新#4 :我现在意识到那些未定义的引用错误是链接器错误。如果我从我的Makefile中删除-L / usr / local / ssl / lib,我不会得到错误(但它链接到OpenSSL 0.9.8)。 / usr / local / ssl / lib /的内容是:

  $ ls / usr / local / ssl / lib / 
engines libcrypto.a libssl.a pkgconfig

我添加了-lcrypto,错误消失了。

解决方案

此处

 #tar -xf openssl-1.0.0a .tar.gz 
#cd openssl-1.0.0a
#./config
#sudo make install

默认情况下它在/ usr / local / ssl中



当你构建时,你需要告诉gcc来查找/ usr / local / ssl / include中的头文件,并链接到/ usr / local / ssl / lib中的libs。您可以通过执行以下操作来指定:

  gcc test.c -o test -I / usr / local / ssl / include -L / usr / local / ssl / lib -lssl -lcrypto 

EDIT 不要覆盖任何系统库。最好在/ usr / local中保留新的库。覆盖Ubuntu的默认值可能危害你的健康和破坏你的系统。



此外,我错了路径,我刚刚在Ubuntu 10.04 VM。固定。



注意,没有必要更改LD_LIBRARY_PATH,因为你链接的openssl库默认是静态库(至少在默认情况下 - 可能有一种方法将它们配置为./config步骤中的动态库)



您可能需要链接到libcrypto,因为您使用的是在libcrypto包中构建和定义的一些调用。



编辑2 添加了 -lcrypto 到gcc行。


You can consider this a follow-up question to How do I install the OpenSSL C++ library on Ubuntu?

I'm trying to build some code on Ubuntu 10.04 LTS that requires OpenSSL 1.0.0.

Ubuntu 10.04 LTS comes with OpenSSL 0.9.8k:

$ openssl version
OpenSSL 0.9.8k 25 Mar 2009

So after running sudo apt-get install libssl-dev and building, running ldd confirms I've linked in 0.9.8:

$ ldd foo
        ...
        libssl.so.0.9.8 => /lib/i686/cmov/libssl.so.0.9.8 (0x00110000)
        ...
        libcrypto.so.0.9.8 => /lib/i686/cmov/libcrypto.so.0.9.8 (0x002b0000)
        ...

How do I install OpenSSL 1.0.0 and the 1.0.0 development package?

Update: I'm writing this update after reading SB's answer (but before trying it), because it's clear I need to explain that the obvious solution of downloading and installing OpenSSL 1.0.0 doesn't work:

After successfully doing the following (recommended in the INSTALL file):

  $ ./config
  $ make
  $ make test
  $ make install

...I still get:

OpenSSL 0.9.8k 25 Mar 2009

...and:

$ sudo apt-get install libssl-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libssl-dev is already the newest version.
The following packages were automatically installed and are no longer required:
  linux-headers-2.6.32-21 linux-headers-2.6.32-21-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

...and (just to make sure) after rebuilding my code, ldd still returns the same thing.

Update #2: I added the "-I/usr/local/ssl/include" and "-L/usr/local/ssl/lib" options (suggested by SB) to my makefile, but I'm now getting a bunch of undefine reference compile errors, for example:

/home/dspitzer/foo/foo.cpp:86: undefined reference to `BIO_f_base64'
/home/dspitzer/foo/foo.cpp:86: undefined reference to `BIO_new'

/usr/local/ssl/include/ contains only an openssl directory (which contains numerous .h files), so I also tried "-I/usr/local/ssl/include/openssl" but got the same errors.

Update #3: I tried changing the OpenSSL includes from (for example):

#include <openssl/bio.h>

...to:

#include "openssl/bio.h"

...in the .cpp source file but still get the same undefined reference errors.

Update #4: I now realize those undefined reference errors are linker errors. If I remove the "-L/usr/local/ssl/lib" from my Makefile, I don't get the errors (but it links to OpenSSL 0.9.8). The contents of /usr/local/ssl/lib/ are:

$ ls /usr/local/ssl/lib/
engines  libcrypto.a  libssl.a  pkgconfig

I added -lcrypto, and the errors went away.

解决方案

Get the 1.0.0a source from here.

# tar -xf openssl-1.0.0a.tar.gz
# cd openssl-1.0.0a
# ./config
# sudo make install

This puts it in /usr/local/ssl by default

When you build, you need to tell gcc to look for the headers in /usr/local/ssl/include and link with libs in /usr/local/ssl/lib. You can specify this by doing something like:

gcc test.c -o test -I/usr/local/ssl/include -L/usr/local/ssl/lib -lssl -lcrypto

EDIT DO NOT overwrite any system libraries. It's best to keep new libs in /usr/local. Overwriting Ubuntu defaults can be hazardous to your health and break your system.

Additionally, I was wrong about the paths as I just tried this in Ubuntu 10.04 VM. Fixed.

Note, there is no need to change LD_LIBRARY_PATH since the openssl libs you link against by default are static libs (at least by default - there might be a way to configure them as dynamic libs in the ./config step)

You may need to link against libcrypto because you are using some calls that are built and defined in the libcrypto package. Openssl 1.0.0 actually builds two libraries, libcrypto and libssl.

EDIT 2 Added -lcrypto to gcc line.

这篇关于如何在Ubuntu上针对OpenSSL 1.0.0安装和构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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