我试图让OpenSSL工作,但它似乎有一个链接的问题。 这是我做的:
#include <errno.h> #include <malloc.h> #include <resolv.h> #include <openssl/bio.h> #include <openssl/ssl.h> int main(void) { SSL_load_error_strings(); return EXIT_SUCCESS; }
all: main.o cc -o main main.o -L/usr/local/ssl/lib/ -lcrypto -lssl main.o: main.c cc -c -Wall main.c -I/usr/local/ssl/include/ -o main.o
cc -o main main.o -L / usr / local / ssl / lib / -lcrypto -lssl /usr/local/ssl/lib//libssl.a(ssl_err2.o):函数SSL_load_error_strings': ssl_err2.c:(.text+0x4): undefined reference to
ERR_load_crypto_strings的SSL_load_error_strings': ssl_err2.c:(.text+0x4): undefined reference to
'/usr/local/ssl/lib//libssl.a(ssl_err.o):在函数ERR_load_SSL_strings': ssl_err.c:(.text+0xc): undefined reference to
(.text ERR_load_strings' ssl_err.c:(.text+0x3c): undefined reference to
ERR_load_strings'collect2:ld返回1退出状态make:*** [所有]错误ERR_func_error_string'ssl_err.c :(。text + 0x28):未定义引用ERR_load_strings' ssl_err.c:(.text+0x3c): undefined reference to
1
我究竟做错了什么?
干杯亚历克斯
正如scott_n在maillist上回答的,但是为了这里的记录,交换顺序为-lssl -lcrypto
。
说明:对于几乎所有系统中的一般静态C库,如libxxx.a
等库文件的成员只有在定义了已经链接的翻译单元(即,在命令行中左侧) 引用的内容时才被链接器拉入。 OpenSSL libssl拥有(许多)对libcrypto的引用。 如果先链接-lcrypto,那么这些引用还没有被看到,所以libcrypto文件没有链接。 那么你链接-lssl并创建不满意的参考。 在相互依赖的情况下,也称为递归依赖,您可能需要重复一个类似-lcrypto -lssl -lcrypto
的库,但是OpenSSL没有这样的“后退”引用。