简体   繁体   English

C ++静态交叉编译在LibCurl和OpenSSL上失败

[英]C++ static cross-compilation failing on LibCurl and OpenSSL

I have a C++ application which depends on both Libcurl (nghttp2 for HTTP/2.0) and OpenSSL to work. 我有一个C ++应用程序,它同时依赖Libcurl(对于HTTP / 2.0为nghttp2)和OpenSSL均可工作。 However, since I don't want any DLL-dependencies I would like to build my application statically (I have the static libraries). 但是,由于我不希望任何DLL依赖关系,因此我想静态地构建应用程序(我有静态库)。 However, I can't get it to work with the underneath command which is cross-compiling from 64-bit Linux for 32-bit Windows, resulting in the errors shown below: 但是,我无法将其与从32位Windows的64位Linux交叉编译的底层命令一起使用,导致出现以下错误:

The Build command: 生成命令:

i686-w64-mingw32-g++ -Wall Programm.cpp -o Programm.exe -I/opt/mingw64/Win32/include -L/opt/mingw64/Win32/lib -I/Software -I/Software/Deps -lcurl -static-libgcc -static-libstdc++ -lcrypto -lssl -lws2_32 -std=c++11 -static -DCURL_STATICLIB

results in these errors: 导致以下错误:

[REMOVED BECAUSE OF TO LARGE BODY] [因身体大而被删除]

UPDATE 更新

I have modified my build command to: 我已将构建命令修改为:

i686-w64-mingw32-g++ -Wall Programm.cpp -o Programm.exe -I/opt/mingw64/Win32/include -L/Software -I/Software/Deps -static-libgcc -static-libstdc++ -lcurl -lnghttp2 -lssl -lcrypto -DCURL_STATICLIB -lpthread -lws2_32 -std=c++11 -static

This leads to the following errors: 这导致以下错误:

/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x47): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x77): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xaf): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x448): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x4ac): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x5d4): more undefined references to `_imp__nghttp2_session_get_stream_user_data' follow
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x6ee): undefined reference to `_imp__nghttp2_session_want_write'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x75e): undefined reference to `_imp__nghttp2_priority_spec_init'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x7e2): undefined reference to `_imp__nghttp2_submit_priority'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x7ef): undefined reference to `_imp__nghttp2_session_send'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x8d3): undefined reference to `_imp__nghttp2_session_del'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x94d): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xb43): undefined reference to `_imp__nghttp2_submit_rst_stream'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xb4e): undefined reference to `_imp__nghttp2_is_fatal'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xb69): undefined reference to `_imp__nghttp2_session_get_remote_settings'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xcdb): undefined reference to `_imp__nghttp2_submit_rst_stream'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xce4): undefined reference to `_imp__nghttp2_is_fatal'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xda8): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xe80): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xeca): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xf6d): undefined reference to `_imp__nghttp2_session_want_read'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xf87): undefined reference to `_imp__nghttp2_session_want_write'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0xfc7): undefined reference to `_imp__nghttp2_session_mem_recv'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x1036): undefined reference to `_imp__nghttp2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x11c5): undefined reference to `_imp__nghttp2_http2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x1298): undefined reference to `_imp__nghttp2_session_resume_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x12ca): undefined reference to `_imp__nghttp2_is_fatal'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x176c): undefined reference to `_imp__nghttp2_submit_request'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x17bb): undefined reference to `_imp__nghttp2_session_send'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x17f9): undefined reference to `_imp__nghttp2_session_resume_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x1d0c): undefined reference to `_imp__nghttp2_session_mem_recv'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x1d19): undefined reference to `_imp__nghttp2_is_fatal'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x1f9e): undefined reference to `_imp__nghttp2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2037): undefined reference to `_imp__nghttp2_session_callbacks_new'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2071): undefined reference to `_imp__nghttp2_session_callbacks_set_send_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2086): undefined reference to `_imp__nghttp2_session_callbacks_set_on_frame_recv_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x209b): undefined reference to `_imp__nghttp2_session_callbacks_set_on_invalid_frame_recv_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x20b0): undefined reference to `_imp__nghttp2_session_callbacks_set_on_data_chunk_recv_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x20c5): undefined reference to `_imp__nghttp2_session_callbacks_set_before_frame_send_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x20da): undefined reference to `_imp__nghttp2_session_callbacks_set_on_frame_send_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x20ef): undefined reference to `_imp__nghttp2_session_callbacks_set_on_frame_not_send_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2104): undefined reference to `_imp__nghttp2_session_callbacks_set_on_stream_close_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2119): undefined reference to `_imp__nghttp2_session_callbacks_set_on_begin_headers_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x212e): undefined reference to `_imp__nghttp2_session_callbacks_set_on_header_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2143): undefined reference to `_imp__nghttp2_session_callbacks_set_error_callback'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x215e): undefined reference to `_imp__nghttp2_session_client_new'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x216d): undefined reference to `_imp__nghttp2_session_callbacks_del'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x21b7): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x21e7): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x22bc): undefined reference to `_imp__nghttp2_version'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x22f2): undefined reference to `_imp__nghttp2_http2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2510): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2555): undefined reference to `_imp__nghttp2_submit_rst_stream'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2631): undefined reference to `_imp__nghttp2_pack_settings_payload'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2751): undefined reference to `_imp__nghttp2_session_resume_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x298c): undefined reference to `_imp__nghttp2_submit_settings'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x29bd): undefined reference to `_imp__nghttp2_session_set_local_window_size'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2a41): undefined reference to `_imp__nghttp2_session_upgrade'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2a54): undefined reference to `_imp__nghttp2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2a85): undefined reference to `_imp__nghttp2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2ab5): undefined reference to `_imp__nghttp2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2afb): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2b49): undefined reference to `_imp__nghttp2_session_mem_recv'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2b54): undefined reference to `_imp__nghttp2_is_fatal'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2b88): undefined reference to `_imp__nghttp2_strerror'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-http2.o):http2.c:(.text+0x2bb5): undefined reference to `_imp__nghttp2_strerror'
collect2: error: ld returned 1 exit status

My libCurl build command: 我的libCurl构建命令:

wget https://curl.haxx.se/download/curl-7.56.1.tar.gz
tar xf curl-7.56.1.tar.gz 
cd curl-7.56.1/
./configure --host=i686-w64-mingw32 --prefix=/opt/mingw64/Win32 --with-ssl=/opt/mingw64/Win32 --with-nghttp2=/opt/mingw64/Win32 --disable-ldap --disable-ldaps curl_LDFLAGS=-all-static
make
make install

My build configuration for LibCurl: 我的LibCurl的构建配置:

curl version:     7.56.1
  Host setup:       i686-w64-mingw32
  Install prefix:   /opt/mingw64/Win32
  Compiler:         i686-w64-mingw32-gcc
  SSL support:      enabled (OpenSSL)
  SSH support:      no      (--with-libssh2)
  zlib support:     no      (--with-zlib)
  GSS-API support:  no      (--with-gssapi)
  TLS-SRP support:  enabled
  resolver:         POSIX threaded
  IPv6 support:     enabled
  Unix sockets support: no      (--enable-unix-sockets)
  IDN support:      no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   no
  ca cert path:     no
  ca fallback:      no
  LDAP support:     no      (--enable-ldap / --with-ldap-lib / --with-lber-lib)
  LDAPS support:    no      (--enable-ldaps)
  RTSP support:     enabled
  RTMP support:     no      (--with-librtmp)
  metalink support: no      (--with-libmetalink)
  PSL support:      no      (libpsl not found)
  HTTP2 support:    enabled (nghttp2)
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP

You have a few link-order errors. 您有一些链接顺序错误。 The C and C++ linkers are greedy when using static libraries. 使用静态库时,C和C ++链接器贪婪。 If they don't need a symbol by the time they see it, they prune it away. 如果他们在看到符号时不需要符号,则将其修剪掉。 This means you have to be somewhat careful about the order you specify libraries on the command-line. 这意味着您必须对在命令行上指定库的顺序有所注意。 You need to put the consumer .a first, and the supplier .a after. 您需要先将消费者.a放在后面,然后将供应商.a放在后面。

So, in the section of errors like: 因此,在错误部分中,例如:

/opt/mingw64/Win32/lib/libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x6da): undefined reference to `COMP_CTX_free'
/opt/mingw64/Win32/lib/libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x6f2): undefined reference to `COMP_CTX_free'
...

These come because libcrypto was encountered before libssl (which depends on it). 这些是因为libcrypto在libssl之前遇到过(取决于它)。 You can eliminate these by moving -lssl before -lcrypto . 您可以通过将-lssl移至-lssl之前来消除这些-lcrypto

For the ones like 对于像

/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-asyn-thread.o):asyn-thread.c:(.text+0x11): undefined reference to `pthread_mutex_destroy'
/opt/mingw64/Win32/lib/libcurl.a(libcurl_la-asyn-thread.o):asyn-thread.c:(.text+0xb8): undefined reference to `pthread_mutex_lock'

Your libcurl is looking for libpthread, so you need to put -lpthread after -lcurl. 您的libcurl正在寻找libpthread,因此您需要将-lpthread放在-lcurl 之后 It looks like libcurl is also looking for an ldap implementation...I'm not really familliar with that, but there's probably a -lldap missing somewhere (presuming libldap). 似乎libcurl也在寻找ldap实现...我对此并不陌生,但是-lldap可能在-lldap缺失(假设是libldap)。 Lastly, I don't see your nghttp library anywhere on the command-line. 最后,在命令行上的任何地方都看不到您的nghttp库。 It looks like it should follow -lcurl as well. 看起来它也应该遵循-lcurl

That leaves the missing libcurl imports at the top; 这将缺少的libcurl导入放在顶部; I don't have any idea there. 我在那里没有任何想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM