I try to compile a library on linux. this libary uses <openssl/sha.h>
library. I have included this library in source file. After that, i use flag -lssl
and flag -lcrypto
to compile this project. So here is my command :
我尝试在linux上编译一个库。这个库使用
gcc -g -Wall -lssl -lcrypto -o bt_client file_a.c file_b.c
gcc -g -Wall -lssl -lcrypto -o bt_client file_a.c file_b.c
But I meet error :
但我遇到了错误:
undefined reference to `SHA1' at line 130
Code at line 130 is :
第130行的代码是:
SHA1((unsigned char *) null_padded_name, 20, (unsigned char *)name_sha1);
Do I miss something ? Please correct me. Thanks :)
我错过了什么吗?请指正。谢谢 :)
3 个解决方案
#1
3
When you link your application, the linker looks for dependencies in the order you give them on the command line.
链接应用程序时,链接器将按照您在命令行上提供的顺序查找依赖项。
So if you add a library (like -lssl
) before the source/object file that depends on that library, the linker will not find any dependencies and ignore the library.
因此,如果在依赖于该库的源/目标文件之前添加库(如-lssl),则链接器将找不到任何依赖项并忽略该库。
This means that you must always put libraries last on the command line.
这意味着您必须始终将库放在命令行上。
#2
7
Try this:
gcc -g -Wall -o bt_client file_a.c file_b.c -lssl -lcrypto
If you are sure that symbol SHA1
exists in libssl.so
or libcrypto.so
.
如果您确定libssl.so或libcrypto.so中存在符号SHA1。
#3
4
You need to provide -lssl and -lcrypto at the end of the command line:
您需要在命令行的末尾提供-lssl和-lcrypto:
gcc -g -Wall -o bt_client file_a.c file_b.c -lssl -lcrypto
#1
3
When you link your application, the linker looks for dependencies in the order you give them on the command line.
链接应用程序时,链接器将按照您在命令行上提供的顺序查找依赖项。
So if you add a library (like -lssl
) before the source/object file that depends on that library, the linker will not find any dependencies and ignore the library.
因此,如果在依赖于该库的源/目标文件之前添加库(如-lssl),则链接器将找不到任何依赖项并忽略该库。
This means that you must always put libraries last on the command line.
这意味着您必须始终将库放在命令行上。
#2
7
Try this:
gcc -g -Wall -o bt_client file_a.c file_b.c -lssl -lcrypto
If you are sure that symbol SHA1
exists in libssl.so
or libcrypto.so
.
如果您确定libssl.so或libcrypto.so中存在符号SHA1。
#3
4
You need to provide -lssl and -lcrypto at the end of the command line:
您需要在命令行的末尾提供-lssl和-lcrypto:
gcc -g -Wall -o bt_client file_a.c file_b.c -lssl -lcrypto