How to static link with mingw x64 C++ runtime and openssl? [message #1848823] |
Sat, 18 December 2021 15:43 |
Alvaro Cordova Messages: 1 Registered: December 2021 |
Junior Member |
|
|
I have this small https client thant compiles and links OK with Eclipse CDT , mingw x64 and openssl 1.1.1, so far so good.
In order to run the EXE in another PC I need to distribute the EXE with these DLLs, all in the same folder, it's cool and simple, but I would like to use a single EXE if possible:
HttpClient.exe
libcrypto-1_1-x64.dll
libgcc_s_seh-1.dll
libssl-1_1-x64.dll
libstdc++-6.dll
libwinpthread-1.dll
Regular link command:
'Invoking: Cross G++ Linker'
g++ -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib" -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\lib" -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\lib" -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0" -o "HttpClient" ./src/HttpClient.o -lcrypto -lssl -lcrypt32 -lws2_32
'Finished building target: HttpClient'
' '
11:36:01 Build Finished. 0 errors, 0 warnings. (took 342ms)
If I add the -static flag to the G++ command line, using /properties/C++ build/settings/G++ linker->Command textbox
These errors are thrown when I try to build:
'Invoking: Cross G++ Linker'
g++ -static -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib" -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\lib" -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32\lib" -L"C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0" -o "HttpClient" ./src/HttpClient.o -lcrypto -lssl -lcrypt32 -lws2_32
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl3_record.o):ssl3_record.c:(.text+0x22f): undefined reference to `COMP_expand_block'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl3_record.o):ssl3_record.c:(.text+0x2b7): undefined reference to `COMP_compress_block'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl3_record.o):ssl3_record.c:(.text+0x1f24): undefined reference to `COMP_expand_block'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl3_record.o):ssl3_record.c:(.text+0x2c3e): undefined reference to `COMP_expand_block'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_cert.o):ssl_cert.c:(.text+0x18cd): undefined reference to `PEM_read_bio_X509'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_cert.o):ssl_cert.c:(.text+0x1aa5): undefined reference to `PEM_read_bio_X509'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_cert.o):ssl_cert.c:(.text+0x20ff): undefined reference to `X509_verify_cert_error_string'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_ciph.o):ssl_ciph.c:(.text+0x3e1): undefined reference to `COMP_get_type'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_ciph.o):ssl_ciph.c:(.text+0x420): undefined reference to `COMP_get_name'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_ciph.o):ssl_ciph.c:(.text+0x1cf1): undefined reference to `EVP_enc_null'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_ciph.o):ssl_ciph.c:(.text+0x356a): undefined reference to `COMP_get_type'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_ciph.o):ssl_ciph.c:(.text+0x3716): undefined reference to `COMP_get_name'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0xf3c): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0xf53): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x513b): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x5154): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x6496): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x64af): more undefined references to `COMP_CTX_free' follow
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x7a69): undefined reference to `X509_LOOKUP_hash_dir'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x7ab9): undefined reference to `X509_LOOKUP_file'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8774): undefined reference to `OCSP_response_get1_basic'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8797): undefined reference to `OCSP_resp_count'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x87a9): undefined reference to `OCSP_resp_get0'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x87c1): undefined reference to `OCSP_SINGLERESP_get1_ext_d2i'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x89c4): undefined reference to `CT_POLICY_EVAL_CTX_new'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x89ef): undefined reference to `CT_POLICY_EVAL_CTX_set1_cert'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x89fa): undefined reference to `CT_POLICY_EVAL_CTX_set1_issuer'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8a10): undefined reference to `CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8a32): undefined reference to `CT_POLICY_EVAL_CTX_set_time'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8a9c): undefined reference to `CT_POLICY_EVAL_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8ad0): undefined reference to `CT_POLICY_EVAL_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x8b10): undefined reference to `CT_POLICY_EVAL_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0xa22d): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0xa246): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x772d): undefined reference to `COMP_CTX_get_method'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x774d): undefined reference to `COMP_CTX_get_method'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x7a55): undefined reference to `X509_STORE_set_default_paths'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_lib.o):ssl_lib.c:(.text+0x7b05): undefined reference to `X509_STORE_load_locations'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0xa18): undefined reference to `PEM_read_bio_X509_AUX'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0xac7): undefined reference to `PEM_read_bio_X509'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0xc73): undefined reference to `PEM_read_bio_X509'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0xddf): undefined reference to `PEM_read_bio_X509'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0x116e): undefined reference to `PEM_read_bio_RSAPrivateKey'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0x17ff): undefined reference to `PEM_read_bio_X509'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_rsa.o):ssl_rsa.c:(.text+0x1b9e): undefined reference to `PEM_read_bio_RSAPrivateKey'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_lib.o):t1_lib.c:(.text+0x4698): undefined reference to `BN_get_rfc3526_prime_2048'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_lib.o):t1_lib.c:(.text+0x4751): undefined reference to `BN_get_rfc3526_prime_3072'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_lib.o):t1_lib.c:(.text+0x4761): undefined reference to `BN_get_rfc3526_prime_8192'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_lib.o):t1_lib.c:(.text+0x4771): undefined reference to `BN_get_rfc3526_prime_4096'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_lib.o):t1_lib.c:(.text+0x4781): undefined reference to `BN_get_rfc2409_prime_1024'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0x642): undefined reference to `SRP_Calc_B'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0x687): undefined reference to `SRP_get_default_gN'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0x70c): undefined reference to `SRP_create_verifier_BN'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0x98f): undefined reference to `SRP_Verify_A_mod_N'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0x9b4): undefined reference to `SRP_Calc_u'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0x9ed): undefined reference to `SRP_Calc_server_key'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0xaf1): undefined reference to `SRP_Verify_B_mod_N'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0xb16): undefined reference to `SRP_Calc_u'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0xb64): undefined reference to `SRP_Calc_x'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0xba2): undefined reference to `SRP_Calc_client_key'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0xe91): undefined reference to `SRP_check_known_gN_param'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(tls_srp.o):tls_srp.c:(.text+0xf44): undefined reference to `SRP_Calc_A'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(s3_enc.o):s3_enc.c:(.text+0x91): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(s3_enc.o):s3_enc.c:(.text+0xaa): undefined reference to `COMP_CTX_new'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(s3_enc.o):s3_enc.c:(.text+0x1f3): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(s3_enc.o):s3_enc.c:(.text+0x20c): undefined reference to `COMP_CTX_new'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_conf.o):ssl_conf.c:(.text+0x365): undefined reference to `X509_STORE_load_locations'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_conf.o):ssl_conf.c:(.text+0xf37): undefined reference to `X509_STORE_load_locations'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_conf.o):ssl_conf.c:(.text+0xfc7): undefined reference to `X509_STORE_load_locations'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(ssl_conf.o):ssl_conf.c:(.text+0x1055): undefined reference to `X509_STORE_load_locations'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_enc.o):t1_enc.c:(.text+0x3ae): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_enc.o):t1_enc.c:(.text+0x3c7): undefined reference to `COMP_CTX_new'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_enc.o):t1_enc.c:(.text+0x65a): undefined reference to `COMP_CTX_free'
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\opt\lib\libssl.a(t1_enc.o):t1_enc.c:(.text+0x673): undefined reference to `COMP_CTX_new'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:60: HttpClient] Error 1
Any help or guidance would be greatly appreciated.
Platform used:
Eclipse CDT Version: 2021-12 (4.22.0)
Build id: 20211202-1639
OpenSSL 1.1.1
g++ (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0
Thank you,
Martin
|
|
|
Re: How to static link with mingw x64 C++ runtime and openssl? [message #1848825 is a reply to message #1848823] |
Sat, 18 December 2021 16:35 |
Tauno Voipio Messages: 742 Registered: August 2014 |
Senior Member |
|
|
The dynamic libraries are different beasts from collections of object files. They need to be along as is, or you do need static versions of the files for linking.
A fully static link is not necessary with the static libraries: the combined executable can still refer to dynamic system libraries. A fully statically linked executable is typically huge.
--
Tauno Voipio
|
|
|
Powered by
FUDForum. Page generated in 0.01825 seconds