报错:undefined reference to `OPENSSL_init_ssl'

报错:

root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/test/2_file/https# gcc -o test test.c  -lcrypto
/tmp/ccmg6lsM.o: In function `sslConnect':
test.c:(.text+0x134): undefined reference to `OPENSSL_init_ssl'
test.c:(.text+0x143): undefined reference to `OPENSSL_init_ssl'
test.c:(.text+0x157): undefined reference to `TLS_client_method'
test.c:(.text+0x15f): undefined reference to `SSL_CTX_new'
test.c:(.text+0x193): undefined reference to `SSL_new'
test.c:(.text+0x1cf): undefined reference to `SSL_set_fd'
test.c:(.text+0x1f2): undefined reference to `SSL_connect'
/tmp/ccmg6lsM.o: In function `sslDisconnect':
test.c:(.text+0x258): undefined reference to `SSL_shutdown'
test.c:(.text+0x268): undefined reference to `SSL_free'
test.c:(.text+0x285): undefined reference to `SSL_CTX_free'
/tmp/ccmg6lsM.o: In function `sslRead':
test.c:(.text+0x37b): undefined reference to `SSL_read'
/tmp/ccmg6lsM.o: In function `sslWrite':
test.c:(.text+0x430): undefined reference to `SSL_write'
collect2: error: ld returned 1 exit status
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/test/2_file/https#

解决方法: 加上参数 “-lssl

root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/test/2_file/https# gcc -o test test.c  -lcrypto -lssl
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/test/2_file/https# ls
test  test.c
root@ubuntu:/mnt/hgfs/Ubuntu12.04-share/test/2_file/https# 

你可能感兴趣的:(Errors,OpenSSL)