当前位置: 技术问答>linux和unix
openssl gcc编译时出错
来源: 互联网 发布时间:2017-01-02
本文导语: 本人巨新的新手,前来取经~ 我用的是linux版本是ubuntu 9.10 gcc版本是4.4.1 把openssl头文件放到了usr/include/openssl下 libcrpto.a 放在home/xiahuangshuai/ssl/lib下 在用gcc编译的时候 用 gcc ssl_client.c -o client -lcrypto 它报的是 /usr/bi...
本人巨新的新手,前来取经~
我用的是linux版本是ubuntu 9.10 gcc版本是4.4.1
把openssl头文件放到了usr/include/openssl下 libcrpto.a 放在home/xiahuangshuai/ssl/lib下
在用gcc编译的时候
用
gcc ssl_client.c -o client -lcrypto
它报的是
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
用
gcc ssl_client.c -o client -I /usr/include/openssl -L /home/xiahuangshuai/ssl/lib -lcrypto
或者
gcc ssl_client.c -o client -L /home/xiahuangshuai/ssl/lib -lcrypto
的时候它报的是
/tmp/cc2wd7MV.o: In function `ShowCerts':
ssl_client.c:(.text+0xd): undefined reference to `SSL_get_peer_certificate'
/tmp/cc2wd7MV.o: In function `main':
ssl_client.c:(.text+0x126): undefined reference to `SSL_library_init'
ssl_client.c:(.text+0x130): undefined reference to `SSL_load_error_strings'
ssl_client.c:(.text+0x135): undefined reference to `SSLv23_client_method'
ssl_client.c:(.text+0x13d): undefined reference to `SSL_CTX_new'
ssl_client.c:(.text+0x299): undefined reference to `SSL_new'
ssl_client.c:(.text+0x2b1): undefined reference to `SSL_set_fd'
ssl_client.c:(.text+0x2bd): undefined reference to `SSL_connect'
ssl_client.c:(.text+0x2dd): undefined reference to `SSL_get_current_cipher'
ssl_client.c:(.text+0x2e5): undefined reference to `SSL_CIPHER_get_name'
ssl_client.c:(.text+0x357): undefined reference to `SSL_write'
ssl_client.c:(.text+0x3ce): undefined reference to `SSL_shutdown'
ssl_client.c:(.text+0x3da): undefined reference to `SSL_free'
ssl_client.c:(.text+0x3f2): undefined reference to `SSL_CTX_free'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x2d): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x43): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4d): undefined reference to `dlclose'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x8f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0xe9): undefined reference to `dlerror'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x491): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x570): undefined reference to `dlerror'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x5f1): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x6d0): undefined reference to `dlerror'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x735): undefined reference to `dlclose'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x817): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x88e): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x8d5): undefined reference to `dlerror'
collect2: ld returned 1 exit status
各位大大,本人菜鸟,若解答尽量详细点,感激不尽。
我用的是linux版本是ubuntu 9.10 gcc版本是4.4.1
把openssl头文件放到了usr/include/openssl下 libcrpto.a 放在home/xiahuangshuai/ssl/lib下
在用gcc编译的时候
用
gcc ssl_client.c -o client -lcrypto
它报的是
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
用
gcc ssl_client.c -o client -I /usr/include/openssl -L /home/xiahuangshuai/ssl/lib -lcrypto
或者
gcc ssl_client.c -o client -L /home/xiahuangshuai/ssl/lib -lcrypto
的时候它报的是
/tmp/cc2wd7MV.o: In function `ShowCerts':
ssl_client.c:(.text+0xd): undefined reference to `SSL_get_peer_certificate'
/tmp/cc2wd7MV.o: In function `main':
ssl_client.c:(.text+0x126): undefined reference to `SSL_library_init'
ssl_client.c:(.text+0x130): undefined reference to `SSL_load_error_strings'
ssl_client.c:(.text+0x135): undefined reference to `SSLv23_client_method'
ssl_client.c:(.text+0x13d): undefined reference to `SSL_CTX_new'
ssl_client.c:(.text+0x299): undefined reference to `SSL_new'
ssl_client.c:(.text+0x2b1): undefined reference to `SSL_set_fd'
ssl_client.c:(.text+0x2bd): undefined reference to `SSL_connect'
ssl_client.c:(.text+0x2dd): undefined reference to `SSL_get_current_cipher'
ssl_client.c:(.text+0x2e5): undefined reference to `SSL_CIPHER_get_name'
ssl_client.c:(.text+0x357): undefined reference to `SSL_write'
ssl_client.c:(.text+0x3ce): undefined reference to `SSL_shutdown'
ssl_client.c:(.text+0x3da): undefined reference to `SSL_free'
ssl_client.c:(.text+0x3f2): undefined reference to `SSL_CTX_free'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x2d): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x43): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x4d): undefined reference to `dlclose'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x8f): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0xe9): undefined reference to `dlerror'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x491): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x570): undefined reference to `dlerror'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x5f1): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x6d0): undefined reference to `dlerror'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x735): undefined reference to `dlclose'
/home/xiahuangshuai/ssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x817): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x88e): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x8d5): undefined reference to `dlerror'
collect2: ld returned 1 exit status
各位大大,本人菜鸟,若解答尽量详细点,感激不尽。
|
-I规定头文件路径,-L规定lib路径。
另外执行前:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
另外执行前:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
|
你的openssl的lib不在标准lib下,自己制定一个路径
|
-I规定头文件路径,-L规定lib路径。
另外执行前:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:home/xiahuangshuai/ssl/lib
另外执行前:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:home/xiahuangshuai/ssl/lib
|
是不是要加libssl.so ?
gcc ssl_client.c -o client -I /usr/include/openssl -L /home/xiahuangshuai/ssl/lib -lcrypto -ssl
gcc ssl_client.c -o client -I /usr/include/openssl -L /home/xiahuangshuai/ssl/lib -lcrypto -ssl