在OS X 10.7上使用gcc的OpenSSL [英] OpenSSL with gcc on OS X 10.7

查看:234
本文介绍了在OS X 10.7上使用gcc的OpenSSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X 10.7上使用TextEdit和gcc来制作小型终端程序。我正试图学习如何编程OpenSSL,但我正在编译剧集(由于不推荐使用的问题 - 更多)。我搜索了谷歌搜索,但我所读的一切都是在2011年之前(当问题似乎出现),特定于iOS(我正在为OS X编程,但尝试独立于平台)或谈论使用XCode(我不喜欢 - 我更喜欢TextEdit)。



任何人都可以请指出一个简单的分步过程的正确方向,以了解如何安装OpenSSL程序在OS X上使用gcc?



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




  • 通过macports安装的OpenSSL


  • 我试图编译这个文件: http://saju.net.in/code/misc/openssl_aes.c.txt

  • 我已重新命名为'aes.c',我使用'gcc -o aes aes.c'


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


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

      Brads-MacBook-Air:桌面brad $ gcc -o aes aes.c -lssl -lcrypto -Wno-error =弃用 - 声明
    aes.c :在函数'aes_init'中:
    aes.c:30:警告:不推荐使用'EVP_BytesToKey'(在/usr/include/openssl/evp.h:572声明)
    aes.c:30:警告:'EVP_aes_256_cbc'已弃用(在/usr/include/openssl/evp.h:786处声明)
    aes.c:30:警告:'EVP_sha1'已弃用(在/ usr / include / openssl / evp.h:666)
    aes.c:36:警告:'EVP_CIPHER_CTX_init'已弃用(在/usr/include/openssl/evp.h:636处声明)
    aes.c:37:警告:'EVP_EncryptInit_ex'已弃用(在/usr/include/openssl/evp.h:581处声明)
    aes.c:37:警告:'EVP_aes_256_cbc'已弃用(在/ usr / include / openssl / evp处声明.h:786)
    aes.c:38:警告:'EVP_CIPHER_CTX_init'已弃用(在/ usr / include / openssl声明/evp.h:636)
    aes.c:39:警告:'EVP_DecryptInit_ex'已弃用(在/usr/include/openssl/evp.h:590处声明)
    aes.c:39:警告:'EVP_aes_256_cbc'已弃用(在/usr/include/openssl/evp.h:786处声明)
    aes.c:函数'aes_encrypt':
    aes.c:51:错误:'' AES_BLOCK_SIZE'未声明(在此函数中首次使用)
    aes.c:51:错误:(每个未声明的标识符只报告一次
    aes.c:51:错误:
    aes.c:55:警告:不推荐使用'EVP_EncryptInit_ex'(在/usr/include/openssl/evp.h:581处声明)
    aes.c:59:警告:'EVP_EncryptUpdate'已弃用(在/usr/include/openssl/evp.h:583处声明)
    aes.c:62:警告:'EVP_EncryptFinal_ex'已弃用(在/usr/include/openssl/evp.h:584处声明)
    aes.c:在函数'aes_decrypt'中:
    aes.c:75:错误:'AES_BLOCK_SIZE'未声明(首次在此函数中使用)
    aes.c:77:warning:'EVP_DecryptInit_ex '已弃用(声明d位于/usr/include/openssl/evp.h:590)
    aes.c:78:警告:'EVP_DecryptUpdate'已弃用(在/usr/include/openssl/evp.h:592处声明)
    aes.c:79:警告:'EVP_DecryptFinal_ex'已被弃用(在/usr/include/openssl/evp.h:594处声明)
    aes.c:在函数'main'中:
    aes .c:136:警告:不推荐使用'EVP_CIPHER_CTX_cleanup'(在/usr/include/openssl/evp.h:637声明)
    aes.c:137:警告:'EVP_CIPHER_CTX_cleanup'已弃用(在/ usr处声明) /include/openssl/evp.h:637)


    解决方案

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



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


    I use TextEdit and gcc on OS X 10.7 to make small terminal programs. I'm trying to learn how to program OpenSSL, but I'm having dramas compiling (due to the deprecated issue - more below). I've Googled and searched on SO but everything I read is either pre-2011 (when the issue seemed to appear), specific to iOS (I'm programming for OS X but trying to be platform independent) or talks about using XCode (which I don't - I prefer TextEdit).

    Can anyone please point in the right direction of a simple, step-by-step process for how to install an OpenSSL program on OS X using gcc?

    For the record, this is the exact steps I have taken:

    • OpenSSL installed via macports

    • 'openssl version' returns "OpenSSL 1.0.1e 11 Feb 2013"

    • I'm trying to compile this file: http://saju.net.in/code/misc/openssl_aes.c.txt

    • I've renamed to 'aes.c' and I'm using 'gcc -o aes aes.c'

    • I've tried the following flags (for no result): -lcrypto, lssl, -Wno-error=deprecated-declarations

    The specific output I get from gcc is the following:

    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)
    

    解决方案

    The deprecation warnings are just that, warnings, and can be ignored. The real problem is that the compiler can't see the declaration of the AES_BLOCK_SIZE macro, which is defined to aes.h. So you need to add a #include <openssl/aes.h> to your source code.

    You'll also need to include the -lcrypto linker flag to link against the OpenSSL runtime library; otherwise, you'll get a bunch of "undefined reference" errors.

    这篇关于在OS X 10.7上使用gcc的OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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