首页 > 解决方案 > 使用 gcc 为 HTTPS(OPENSSL)编译 Socket C 程序时出错

问题描述

我正在 Ubuntu 18 上使用 OpenSSL 包准备一个套接字 C 程序。当我尝试使用以下命令编译程序时:

gcc WinSocketClientSSL.c -o WinSocketClientSSL -lssl

我收到以下错误:

/usr/bin/ld: /tmp/ccfr2z39.o: undefined reference to symbol 'OPENSSL_init_crypto@@OPENSSL_1_1_0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libcrypto.so.1.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

我已经尝试使用 target_link_libraries(),因为我的 libssl.a 和 libcrypto.a 文件位于 /usr/lib/x86_64-linux-gnu/ 文件夹中。以下是我的条目:

add_executable(Win_Socket_Client_SSL src/WinSocketClientSSL.c)
target_link_libraries(WinSocketClientSSL /usr/libx86_64-linux-gnu/libssl.a)
target_link_libraries(WinSocketClientSSL /usr/libx86_64-linux-gnu/libcrypto.a)

标签: cgcccmakecompiler-errorsopenssl

解决方案


推荐阅读