linux include 编译,linux-如何使用OpenSSL include编译.c文件?
linux-如何使用OpenSSL include編譯.c文件?
我正在嘗試編譯一個包含以下內容的小.c文件:
#include
#include
#include
#include
在我擁有.c文件的同一文件夾中,我擁有帶有所有這些文件(以及更多文件)的/ openssl,也在突觸包管理器中,我看到安裝了OpenSSL,我正在嘗試使用以下方法進行編譯:
gcc -o Opentest Opentest.c -lcrypto
但我總是得到錯誤:
error: openssl/ssl.h: No such file or directory
error: openssl/rsa.h: No such file or directory
error: openssl/x509.h: No such file or directory
error: openssl/evp.h: No such file or directory
我要編譯的文件只是一個.c文件,沒有Makefile或./configure。
我已經嘗試過:
env CFLAGS=-I/path/to/openssl/
并嘗試再次編譯,但我得到相同的錯誤。
我應該怎么做才能用openssl include進行編譯?
7個解決方案
97 votes
您的包含路徑表明您應該針對系統的OpenSSL安裝進行編譯。 您的軟件包目錄中不應包含.h文件-它應從libssl中提取它們。
普通的OpenSSL軟件包(libssl)不包含.h文件-您還需要安裝開發軟件包。 在Debian,Ubuntu和類似發行版上,它的名稱為libssl-dev,在CentOS,Fedora,Red Hat和類似版本上的名稱為libssl-devel。
caf answered 2019-10-05T09:50:36Z
9 votes
使用-I標志正確地gcc。
-I
-I應指向包含openssl文件夾的目錄。
Borealid answered 2019-10-05T09:51:14Z
6 votes
我的英語不是很好但我在中文網頁上找到了針對此問題的補丁
百勝安裝openssl百勝安裝openssl-devel
安裝此軟件,并在centos 5.4和keepalived-1.2.7中進行測試]
user2317002 answered 2019-10-05T09:51:53Z
4 votes
如果OpenSSL標頭位于當前目錄的./openssl/ssl.h子目錄中,請使用:
gcc -I. -o Opentest Opentest.c -lcrypto
預處理程序希望從-I選項中的“ .”中創建一個名稱,例如“ 2555697279869869125632”,并在尖括號中指定該名稱。 如果您在雙引號中指定了名稱(#include "openssl/ssl.h"),則可能永遠不需要問這個問題。 Unix上的編譯器通常會自動在當前目錄中搜索用雙引號引起來的標頭,但對于在尖括號中引起的標頭則不會這樣做(#include )。 它是實現定義的行為。
您沒有說OpenSSL庫在哪里-您可能需要添加適當的選項和參數來指定它,例如'-L /opt/openssl/lib'。
Jonathan Leffler answered 2019-10-05T09:52:35Z
4 votes
從openssl.pc文件
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: OpenSSL
Description: Secure Sockets Layer and cryptography libraries and tools
Version: 0.9.8g
Requires:
Libs: -L${libdir} -lssl -lcrypto
Libs.private: -ldl -Wl,-Bsymbolic-functions -lz
Cflags: -I${includedir}
您可以從中記下Include目錄路徑和Libs路徑。 現在,包含文件的前綴為-L。因此,您的包含文件選項應為-I//home/username/Programming。
(是的,我從上面的評論中得到了它)
這只是為了刪除有關標頭的日志。 您也可以提供-L選項與-lcrypto庫鏈接。
Praveen S answered 2019-10-05T09:53:23Z
3 votes
您需要包括庫路徑(-L / usr / local / lib /)
gcc -o Opentest Opentest.c -L/usr/local/lib/ -lssl -lcrypto
這個對我有用。
Jeff Pal answered 2019-10-05T09:53:58Z
1 votes
對于此gcc錯誤,您應參考有關搜索路徑的gcc文檔。
簡而言之:
1)如果將尖括號(<>)與#include一起使用,gcc將首先從系統路徑(例如/ usr / local / include和/ usr / include等)搜索頭文件。
2)-Ldir命令行選項指定的路徑將在默認目錄之前搜索。
3)如果在#include中將quotation(“”)與#include“ file”一起使用,則將首先搜索包含當前文件的目錄。
因此,您的問題的答案如下:
1)如果要在源代碼文件夾中使用頭文件,請在#include指令中將<>替換為“”。
2)如果要使用-I命令行選項,請將其添加到編譯命令行中。(如果在環境變量中設置CFLAGS,將不會自動引用它)
3)關于程序包配置(openssl.pc),我認為在構建配置中未明確聲明的情況下不會引用它。
gzh answered 2019-10-05T09:55:15Z
總結
以上是生活随笔為你收集整理的linux include 编译,linux-如何使用OpenSSL include编译.c文件?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (kruskal算法复习+模板)Eddy
- 下一篇: adminer.php下载,Admine