2014-01-09 68 views
1

我在OS X 10.7上使用TextEdit和gcc來製作小型終端程序。我正試圖學習如何編程OpenSSL,但我正在編譯劇集(由於不推薦使用的問題 - 更多)。我搜索了谷歌搜索,但我所讀的一切都是在2011年之前(當問題出現時),特定於iOS(我正在爲OS X編程,但嘗試獨立於平臺)或談論使用XCode(我不 - 我更喜歡TextEdit)。在OS X上使用gcc的OpenSSL 10.7

任何人都可以請指出一個簡單的,一步一步的過程如何在OS X上使用gcc安裝OpenSSL程序的正確方向?

根據記錄,這是我所採取的具體步驟:通過MacPorts的

  • 'OpenSSL的版本' 安裝

    • OpenSSL的返回 「的OpenSSL 1.0.1e 2013年2月11日」

    • 我試圖編譯這個文件:http://saju.net.in/code/misc/openssl_aes.c.txt

    • 我已經改名爲'aes.c',我使用'g立方厘米-o AES aes.c」

    • 我嘗試了以下標誌(有結果):-lcrypto,lssl,-Wno誤差=棄用-聲明

    的具體輸出I從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) 
    
  • +0

    通常情況下,你會避免使用Apple 0.9.8版本的OpenSSL。它缺少TLS 1.1和1.2,缺乏完全支持EC等。要在OS X上構建OpenSSL,請參閱OpenSSL wiki上的[編譯和安裝](https://wiki.openssl.org/index.php/Compilation_and_Installation)。 。我編寫了OS X指令,所以我知道它們的工作原理。 – jww

    回答

    2

    的廢棄警告是正義的,警告,可以忽略不計。真正的問題是,編譯器無法看到AES_BLOCK_SIZE宏的定義爲aes.h的聲明。所以你需要添加一個#include <openssl/aes.h>到你的源代碼。

    您還需要包含-lcrypto鏈接器標誌以鏈接到OpenSSL運行時庫;否則,你會得到一堆「未定義的參考」錯誤。

    +0

    感謝亞當 - 我已經添加了額外的內容,現在程序已經編譯完成。當我運行它雖然我得到了一個分段錯誤...但至少它編譯... :)再次感謝! – user3081739

    +0

    使用該編譯行,它不是**使用ssl庫的macports版本,但操作系統提供了一個。操作系統提供的一個是棄用警告來自 – Petesh

    +0

    嗨Petesh - 你可以請擴展嗎?我如何獲得它使用最新的?謝謝! – user3081739