编译和Ubuntu上联VS的OpenSSL OSX [英] Compiling and linking OpenSSL on Ubuntu vs OSX

查看:206
本文介绍了编译和Ubuntu上联VS的OpenSSL OSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试1,香草链接库

我想使用OpenSSL(所以DTLS更容易使用)的一个补丁版本。 OpenSSL是在

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

/usr/local/openssl-1.0.1c

该./include/openssl子文件夹有一吨的头文件(因为我认为它应该):

The ./include/openssl subfolder has a ton of header files (as I assume it should):

lrwxrwxrwx 1 root root   22 Dec 25 05:49 aes.h -> ../../crypto/aes/aes.h
lrwxrwxrwx 1 root root   24 Dec 25 05:49 asn1.h -> ../../crypto/asn1/asn1.h
lrwxrwxrwx 1 root root   28 Dec 25 05:49 asn1_mac.h -> ../../crypto/asn1/asn1_mac.h
...

GCC链接到包含文件夹,并给了我一个错误 - 它无法找到SSL。我使用或多或少同样的事情,其他人都。这工作,在OSX(10.6),但不是在Ubuntu的:

GCC links to the include folder and gives me an error- it cannot find SSL. I'm using more or less the same thing other people are. This works, on OSX (10.6), but not on Ubuntu:

~$ gcc -L/usr/local/openssl-1.0.1c/include -lssl -lcrypto  -o server server.c
server.c:20:25: fatal error: openssl/ssl.h: No such file or directory
compilation terminated.

2的尝试,符号链接库在/ usr /包含

所以,后来我尝试创建符号链接到我的OpenSSL / usr / include目录:

So, then I try creating a symbolic link to OpenSSL in my /usr/include:

sudo ln -s /usr/local/openssl-1.0.1c/include/openssl /usr/include/openssl

和重新尝试编译:

~$ gcc -L/usr/local/openssl-1.0.1c/include -lssl -lcrypto  -o server server.c
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
make: *** [server] Error 1

为什么第一个方法(即无符号连接)不工作?权限?为什么第二种方法不工作?为什么在OSX这项工作?

推荐答案

与未找到头文件的问题似乎你混淆你的选择。 -L 添加到链接程序库搜索路径的路径,而 -I 添加目录到preprocessor头文件搜索路径。更改 -L -I 来解决这个问题:

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

现在的问题链接是因为你错误地使用 -L 选项告诉链接器查找在include路径库。你需要的路径更改为在库的目录,通常为 LIB 子目录。此外,连接器希望在它们的依赖相反的顺序库,所以把你想在命令行上与去年链接库:

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

这篇关于编译和Ubuntu上联VS的OpenSSL OSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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