【问题标题】:Mingw32 error linking -lcrypto with undefined referencesMingw32 错误链接 -lcrypto 与未定义的引用
【发布时间】:2021-02-25 15:00:28
【问题描述】:

我已经使用 Mingw32 和 MSys 和 Strawberry Perl 编译了 OpenSSL 库。 我用这个论坛帖子作为指南,尽管它已经很老了。 How to build OpenSSL with MinGW in Windows?

一切都很顺利,我想将它编译为静态库并且它可以工作,但是每当我尝试使用 g++ 将库与我的项目一起编译时,我都会收到以下错误,我不知道它们是什么意思。

libcrypto.a(e_capi.o):e_capi.c:(.text+0xf1): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x191): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x5ed): undefined reference to `_imp__CertGetCertificateContextProperty@16'
libcrypto.a(e_capi.o):e_capi.c:(.text+0xbd3): undefined reference to `_imp__CertGetCertificateContextProperty@16'
libcrypto.a(e_capi.o):e_capi.c:(.text+0xd40): undefined reference to `_imp__CertEnumCertificatesInStore@8'
libcrypto.a(e_capi.o):e_capi.c:(.text+0xdd9): undefined reference to `_imp__CertFindCertificateInStore@24'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x3012): undefined reference to `_imp__CertOpenStore@20'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x3051): undefined reference to `_imp__CertEnumCertificatesInStore@8'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x316f): undefined reference to `_imp__CertDuplicateCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x31f1): undefined reference to `_imp__CertCloseStore@8'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x32a5): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x396c): undefined reference to `_imp__CertOpenStore@20'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x39ab): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x39c3): undefined reference to `_imp__CertCloseStore@8'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x3a1f): undefined reference to `_imp__CertEnumCertificatesInStore@8'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x4195): undefined reference to `_imp__CertOpenStore@20'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x4208): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x4221): undefined reference to `_imp__CertCloseStore@8'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x4359): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(e_capi.o):e_capi.c:(.text+0x440d): undefined reference to `_imp__CertFreeCertificateContext@4'
libcrypto.a(b_addr.o):b_addr.c:(.text+0xbe): undefined reference to `_imp__getnameinfo@28'
libcrypto.a(b_addr.o):b_addr.c:(.text+0xf4): undefined reference to `_imp__ntohs@4'
libcrypto.a(b_addr.o):b_addr.c:(.text+0x29a): undefined reference to `gai_strerrorW'
libcrypto.a(b_addr.o):b_addr.c:(.text+0x7c0): undefined reference to `_imp__freeaddrinfo@4'
libcrypto.a(b_addr.o):b_addr.c:(.text+0xae8): undefined reference to `_imp__getaddrinfo@16'
libcrypto.a(b_addr.o):b_addr.c:(.text+0xbc9): undefined reference to `gai_strerrorW'
libcrypto.a(b_addr.o):b_addr.c:(.text+0xcb3): undefined reference to `_imp__getaddrinfo@16'
libcrypto.a(b_addr.o):b_addr.c:(.text+0xd91): undefined reference to `gai_strerrorW'
libcrypto.a(b_sock.o):b_sock.c:(.text+0xdf): undefined reference to `_imp__WSAStartup@8'
libcrypto.a(b_sock.o):b_sock.c:(.text+0xf0): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x2c7): undefined reference to `_imp__WSAStartup@8'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x2d8): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x3c1): undefined reference to `_imp__ntohs@4'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x41c): undefined reference to `_imp__getsockopt@20'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x43a): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x45c): undefined reference to `_imp__gethostbyname@4'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x4ab): undefined reference to `_imp__WSAStartup@8'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x4c2): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x54c): undefined reference to `_imp__WSACleanup@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x56d): undefined reference to `_imp__ioctlsocket@12'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x58a): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x757): undefined reference to `_imp__WSAStartup@8'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x768): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x962): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0x9ec): undefined reference to `_imp__setsockopt@20'
libcrypto.a(b_sock.o):b_sock.c:(.text+0xa25): undefined reference to `_imp__ioctlsocket@12'
libcrypto.a(b_sock.o):b_sock.c:(.text+0xa42): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock.o):b_sock.c:(.text+0xab6): undefined reference to `_imp__getsockname@12'
libcrypto.a(b_sock.o):b_sock.c:(.text+0xb1a): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x27): undefined reference to `_imp__socket@12'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x49): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x11c): undefined reference to `_imp__setsockopt@20'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x157): undefined reference to `_imp__connect@12'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x195): undefined reference to `_imp__setsockopt@20'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x1a6): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x264): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x2ca): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x362): undefined reference to `_imp__bind@12'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x3ba): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x467): undefined reference to `_imp__getsockopt@20'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x47d): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x531): undefined reference to `_imp__setsockopt@20'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5dd): undefined reference to `_imp__listen@8'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x5eb): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x675): undefined reference to `_imp__setsockopt@20'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x686): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x71a): undefined reference to `_imp__setsockopt@20'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x72b): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x792): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x826): undefined reference to `_imp__accept@12'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x867): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x8cb): undefined reference to `_imp__closesocket@4'
libcrypto.a(b_sock2.o):b_sock2.c:(.text+0x8ec): undefined reference to `_imp__closesocket@4'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1b2): undefined reference to `_imp__WSASetLastError@4'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x1d9): undefined reference to `_imp__send@16'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x20a): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x281): undefined reference to `_imp__WSASetLastError@4'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x2a0): undefined reference to `_imp__send@16'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x2da): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x34d): undefined reference to `_imp__WSASetLastError@4'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x370): undefined reference to `_imp__recv@16'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x3c2): undefined reference to `_imp__WSAGetLastError@0'
libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x482): undefined reference to `_imp__WSAGetLastError@0'
collect2.exe: error: ld returned 1 exit status

我使用 VSCode 作为开发环境,这是项目的构建命令,从 tasks.json 中提取:

g++.exe file1.cpp file2.cpp main.cpp -L*folder with the library* -lcrypto -o test.exe

【问题讨论】:

  • 链接器在 Crypt32.lib 和 Ws2_32.lib 中找不到几个函数。您应该将这些链接到您的 exe。
  • @nevilad 如何在 VSCode 中链接这些库? #pragma comment(lib, "ws2_32.lib") 似乎不起作用。如果我包含 ,我仍然会遇到同样的错误
  • 在您的 g++ 命令行中添加 -lws2_32 有帮助吗?
  • @nevilad 非常感谢 :)) -lws2_32 和 -lcrypt32 工作

标签: c++ openssl linker mingw


【解决方案1】:

链接器无法从Crypt32.libWs2_32.lib 中找到几个函数。通过将 -lws2_32 -lcrypt32 添加到 g++ 命令行,将这些链接到您的 exe。

#pragma comment(lib, "ws2_32.lib") 是 Microsoft 特有的功能,g++ 不支持此功能,因此您无法使用此 pragma 链接库。另请参阅此帖子 - #pragma comment(lib, "xxx.lib") equivalent under Linux?

【讨论】:

    猜你喜欢
    • 2014-06-27
    • 1970-01-01
    • 2015-01-23
    • 1970-01-01
    • 2014-04-21
    • 2013-03-15
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多