在OS X 10.7上使用gcc的OpenSSL

时间:2014-01-09 04:42:07

标签: c macos gcc openssl

我在OS X 10.7上使用TextEdit和gcc来制作小型终端程序。我正在尝试学习如何编写OpenSSL,但我正在编写剧集(由于弃用的问题 - 更多内容)。我用Google搜索并搜索了所有内容,但我读到的所有内容都是2011年之前(当问题出现时),特定于iOS(我为OS X编程但尝试独立于平台)或谈论使用XCode(我没有 - 我更喜欢TextEdit。)

任何人都可以指出如何使用gcc在OS X上安装OpenSSL程序的简单逐步过程的正确方向吗?

为了记录,这是我采取的确切步骤:

  • 通过macports安装OpenSSL

  • 'openssl version'返回“OpenSSL 1.0.1e 2013年2月11日”

  • 我正在尝试编译此文件:http://saju.net.in/code/misc/openssl_aes.c.txt

  • 我已将其重命名为'aes.c',而我正在使用'gcc -o aes aes.c'

  • 我尝试了以下标志(没有结果):-lcrypto,lssl,-Wno-error = deprecated-declarations

我从gcc获得的具体输出如下:

Brads-MacBook-Air:Desktop brad$ gcc -o aes aes.c -lssl -lcrypto -Wno-error=deprecated-declarations
aes.c: In function ‘aes_init’:
aes.c:30: warning: ‘EVP_BytesToKey’ is deprecated (declared at /usr/include/openssl/evp.h:572)
aes.c:30: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c:30: warning: ‘EVP_sha1’ is deprecated (declared at /usr/include/openssl/evp.h:666)
aes.c:36: warning: ‘EVP_CIPHER_CTX_init’ is deprecated (declared at /usr/include/openssl/evp.h:636)
aes.c:37: warning: ‘EVP_EncryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:581)
aes.c:37: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c:38: warning: ‘EVP_CIPHER_CTX_init’ is deprecated (declared at /usr/include/openssl/evp.h:636)
aes.c:39: warning: ‘EVP_DecryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:590)
aes.c:39: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c: In function ‘aes_encrypt’:
aes.c:51: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
aes.c:51: error: (Each undeclared identifier is reported only once
aes.c:51: error: for each function it appears in.)
aes.c:55: warning: ‘EVP_EncryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:581)
aes.c:59: warning: ‘EVP_EncryptUpdate’ is deprecated (declared at /usr/include/openssl/evp.h:583)
aes.c:62: warning: ‘EVP_EncryptFinal_ex’ is deprecated (declared at /usr/include/openssl/evp.h:584)
aes.c: In function ‘aes_decrypt’:
aes.c:75: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
aes.c:77: warning: ‘EVP_DecryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:590)
aes.c:78: warning: ‘EVP_DecryptUpdate’ is deprecated (declared at /usr/include/openssl/evp.h:592)
aes.c:79: warning: ‘EVP_DecryptFinal_ex’ is deprecated (declared at /usr/include/openssl/evp.h:594)
aes.c: In function ‘main’:
aes.c:136: warning: ‘EVP_CIPHER_CTX_cleanup’ is deprecated (declared at /usr/include/openssl/evp.h:637)
aes.c:137: warning: ‘EVP_CIPHER_CTX_cleanup’ is deprecated (declared at /usr/include/openssl/evp.h:637)

1 个答案:

答案 0 :(得分:2)

弃用警告只是警告,可以忽略。真正的问题是编译器无法看到AES_BLOCK_SIZE宏的声明,它定义为aes.h。因此,您需要在源代码中添加#include <openssl/aes.h>

您还需要包含-lcrypto链接器标志以链接OpenSSL运行时库;否则,你会得到一堆“未定义的引用”错误。