提问人:hoze 提问时间:9/30/2023 最后编辑:hoze 更新时间:10/2/2023 访问量:93
编译静态 C 程序找不到 curl 函数,即使链接也是如此
Compiling static C program doesn't find curl functions, even though linked
问:
我正在尝试静态编译 C 程序。我尝试在命令行中添加“-static”选项,但仍然出现错误。 这是命令行。
gcc main.c -o main.exe -lcurl -static -L"C:\msys64\mingw64\lib" -lregex -lsqlite3 -lssl -ljansson -liphlpapi -lcrypto -lcrypt32 -w -mwindows
(“C:\msys64\mingw64\lib”路径包括 libcurl.a)
错误:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x3ec): undefined reference to `__imp_curl_global_init'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x403): undefined reference to `__imp_curl_easy_init'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x581): undefined reference to `__imp_curl_easy_setopt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x5a6): undefined reference to `__imp_curl_slist_append'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x6e7): undefined reference to `__imp_curl_easy_perform'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x700): undefined reference to `__imp_curl_easy_cleanup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x713): undefined reference to `__imp_curl_slist_free_all'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x71c): undefined reference to `__imp_curl_global_cleanup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x95a): undefined reference to `__imp_curl_easy_perform'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0xd5a): undefined reference to `__imp_curl_easy_strerror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x113a): undefined reference to `__imp_curl_formadd'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x11fb): undefined reference to `__imp_curl_easy_perform'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x1214): undefined reference to `__imp_curl_formfree'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccz3KeYh.o:main.c:(.text+0x137c): undefined reference to `__imp_curl_easy_strerror'
同一库中还有其他库错误。
错误:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libregex.a(systre.o):(.text+0x1): undefined reference to `tre_regcomp'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libregex.a(systre.o):(.text+0x11): undefined reference to `tre_regfree'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libregex.a(systre.o):(.text+0x21): undefined reference to `tre_regerror'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libregex.a(systre.o):(.text+0x31): undefined reference to `tre_regexec'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0xd5): undefined reference to `__imp_WSAStartup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x103): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x2a5): undefined reference to `__imp_WSAStartup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x2d3): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x397): undefined reference to `__imp_ntohs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x3e3): undefined reference to `__imp_getsockopt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x402): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x413): undefined reference to `__imp_gethostbyname'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x465): undefined reference to `__imp_WSAStartup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x48f): undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\mingw64\lib\libcrypto.a(libcrypto-lib-bio_sock.obj):(.text+0x4fd): undefined reference to `__imp_WSACleanup'
-v 输出:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-13.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Rev2, Built by MSYS2 project)
COLLECT_GCC_OPTIONS='-o' 'main.exe' '-static' '-LC:\msys64\mingw64\lib' '-w' '-mwindows' '-v' '-mtune=generic' '-march=nocona'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/cc1.exe -quiet -v -iprefix C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/ -D_REENTRANT main.c -quiet -dumpbase main.c -dumpbase-ext .c -mwindows -mtune=generic -march=nocona -w -version -o C:\Users\username\AppData\Local\Temp\ccUBzLLV.s
GNU C17 (Rev2, Built by MSYS2 project) version 13.2.0 (x86_64-w64-mingw32)
compiled by GNU C version 13.2.0, GMP version 6.3.0, MPFR version 4.2.0-p12, MPC version 1.3.1, isl version isl-0.26-GMP
warning: MPFR header version 4.2.0-p12 differs from library version 4.2.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/include"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/include"
ignoring nonexistent directory "D:/a/msys64/mingw64/include"
ignoring nonexistent directory "/mingw64/include"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/include-fixed"
ignoring nonexistent directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "D:/a/msys64/mingw64/include"
#include "..." search starts here:
#include <...> search starts here:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/include-fixed
End of search list.
Compiler executable checksum: f9bd18fc84ad3f3a3728d580196f7356
COLLECT_GCC_OPTIONS='-o' 'main.exe' '-static' '-LC:\msys64\mingw64\lib' '-w' '-mwindows' '-v' '-mtune=generic' '-march=nocona'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -W -o C:\Users\username\AppData\Local\Temp\cctKVUpC.o C:\Users\username\AppData\Local\Temp\ccUBzLLV.s
GNU assembler version 2.41 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.41
COMPILER_PATH=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/;C:/msys64/mingw64/bin/../lib/gcc/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/;C:/msys64/mingw64/bin/../lib/gcc/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/;C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../
COLLECT_GCC_OPTIONS='-o' 'main.exe' '-static' '-LC:\msys64\mingw64\lib' '-w' '-mwindows' '-v' '-mtune=generic' '-march=nocona' '-dumpdir' 'main.'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/collect2.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/liblto_plugin.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\username\AppData\Local\Temp\ccmIlYkr.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lgdi32 -plugin-opt=-pass-through=-lcomdlg32 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -m i386pep --subsystem windows -Bstatic -o main.exe C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtbegin.o -LC:\msys64\mingw64\lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../.. C:\Users\username\AppData\Local\Temp\cctKVUpC.o -lcurl -lregex -lsqlite3 -lssl -ljansson -liphlpapi -lcrypto -lcrypt32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 -lpthread -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtend.o
“-wl,-v” 输出:
collect2 version 13.2.0
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe -plugin C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/liblto_plugin.dll -plugin-opt=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\username\AppData\Local\Temp\ccktir8z.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lgdi32 -plugin-opt=-pass-through=-lcomdlg32 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -m i386pep --subsystem windows -Bstatic -o main.exe C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/crt2.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtbegin.o -LC:\msys64\mingw64\lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0 -LC:/msys64/mingw64/bin/../lib/gcc -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/lib -LC:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../.. C:\Users\username\AppData\Local\Temp\cc7Vdy7N.o -lcurl -lregex -lsqlite3 -lssl -ljansson -liphlpapi -lcrypto -lcrypt32 -v -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 -lpthread -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lkernel32 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/default-manifest.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtend.o
GNU ld (GNU Binutils) 2.41
“-wl,--verbose” 输出:
GNU ld (GNU Binutils) 2.41
Supported emulations:
i386pep
i386pe
using internal linker script:
==================================================
/* Default linker script, for normal executables */
/* Copyright (C) 2014-2023 Free Software Foundation, Inc.
Copying and distribution of this script, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. */
OUTPUT_FORMAT(pei-x86-64)
SEARCH_DIR("=/mingw64/x86_64-w64-mingw32/lib"); SEARCH_DIR("=/mingw64/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
SECTIONS
{
/* Make the virtual address and file offset synced if the alignment is
lower than the target page size. */
. = SIZEOF_HEADERS;
. = ALIGN(__section_alignment__);
.text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :
{
KEEP (*(SORT_NONE(.init)))
*(.text)
*(SORT(.text$*))
*(.text.*)
*(.gnu.linkonce.t.*)
*(.glue_7t)
*(.glue_7)
. = ALIGN(8);
/* Note: we always define __CTOR_LIST__ and ___CTOR_LIST__ here,
we do not PROVIDE them. This is because the ctors.o startup
code in libgcc defines them as common symbols, with the
expectation that they will be overridden by the definitions
here. If we PROVIDE the symbols then they will not be
overridden and global constructors will not be run.
See PR 22762 for more details.
This does mean that it is not possible for a user to define
their own __CTOR_LIST__ and __DTOR_LIST__ symbols; if they do,
the content from those variables are included but the symbols
defined here silently take precedence. If they truly need to
be redefined, a custom linker script will have to be used.
(The custom script can just be a copy of this script with the
PROVIDE() qualifiers added).
In particular this means that ld -Ur does not work, because
the proper __CTOR_LIST__ set by ld -Ur is overridden by a
bogus __CTOR_LIST__ set by the final link. See PR 46. */
___CTOR_LIST__ = .;
__CTOR_LIST__ = .;
LONG (-1); LONG (-1);
KEEP (*(.ctors));
KEEP (*(.ctor));
KEEP (*(SORT_BY_NAME(.ctors.*)));
LONG (0); LONG (0);
/* See comment about __CTOR_LIST__ above. The same reasoning
applies here too. */
___DTOR_LIST__ = .;
__DTOR_LIST__ = .;
LONG (-1); LONG (-1);
KEEP (*(.dtors));
KEEP (*(.dtor));
KEEP (*(SORT_BY_NAME(.dtors.*)));
LONG (0); LONG (0);
KEEP (*(SORT_NONE(.fini)))
/* ??? Why is .gcc_exc here? */
*(.gcc_exc)
PROVIDE (etext = .);
KEEP (*(.gcc_except_table))
}
/* The Cygwin32 library uses a section to avoid copying certain data
on fork. This used to be named ".data". The linker used
to include this between __data_start__ and __data_end__, but that
breaks building the cygwin32 dll. Instead, we name the section
".data_cygwin_nocopy" and explicitly include it after __data_end__. */
.data BLOCK(__section_alignment__) :
{
__data_start__ = . ;
*(.data)
*(.data2)
*(SORT(.data$*))
KEEP(*(.jcr))
__data_end__ = . ;
*(.data_cygwin_nocopy)
}
.rdata BLOCK(__section_alignment__) :
{
*(.rdata)
*(SORT(.rdata$*))
. = ALIGN(4);
__rt_psrelocs_start = .;
KEEP(*(.rdata_runtime_pseudo_reloc))
__rt_psrelocs_end = .;
}
__rt_psrelocs_size = __rt_psrelocs_end - __rt_psrelocs_start;
___RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
__RUNTIME_PSEUDO_RELOC_LIST_END__ = .;
___RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;
__RUNTIME_PSEUDO_RELOC_LIST__ = . - __rt_psrelocs_size;
.eh_frame BLOCK(__section_alignment__) :
{
KEEP (*(.eh_frame*))
}
.pdata BLOCK(__section_alignment__) :
{
KEEP(*(.pdata*))
}
.xdata BLOCK(__section_alignment__) :
{
KEEP(*(.xdata*))
}
.bss BLOCK(__section_alignment__) :
{
__bss_start__ = . ;
*(.bss)
*(COMMON)
__bss_end__ = . ;
}
.edata BLOCK(__section_alignment__) :
{
*(.edata)
}
/DISCARD/ :
{
*(.debug$S)
*(.debug$T)
*(.debug$F)
*(.drectve)
*(.note.GNU-stack)
*(.gnu.lto_*)
}
.idata BLOCK(__section_alignment__) :
{
/* This cannot currently be handled with grouped sections.
See pep.em:sort_sections. */
KEEP (SORT(*)(.idata$2))
KEEP (SORT(*)(.idata$3))
/* These zeroes mark the end of the import list. */
LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
. = ALIGN(8);
KEEP (SORT(*)(.idata$4))
__IAT_start__ = .;
SORT(*)(.idata$5)
__IAT_end__ = .;
KEEP (SORT(*)(.idata$6))
KEEP (SORT(*)(.idata$7))
}
.CRT BLOCK(__section_alignment__) :
{
___crt_xc_start__ = . ;
KEEP (*(SORT(.CRT$XC*))) /* C initialization */
___crt_xc_end__ = . ;
___crt_xi_start__ = . ;
KEEP (*(SORT(.CRT$XI*))) /* C++ initialization */
___crt_xi_end__ = . ;
___crt_xl_start__ = . ;
KEEP (*(SORT(.CRT$XL*))) /* TLS callbacks */
/* ___crt_xl_end__ is defined in the TLS Directory support code */
___crt_xp_start__ = . ;
KEEP (*(SORT(.CRT$XP*))) /* Pre-termination */
___crt_xp_end__ = . ;
___crt_xt_start__ = . ;
KEEP (*(SORT(.CRT$XT*))) /* Termination */
___crt_xt_end__ = . ;
}
/* Windows TLS expects .tls$AAA to be at the start and .tls$ZZZ to be
at the end of the .tls section. This is important because _tls_start MUST
be at the beginning of the section to enable SECREL32 relocations with TLS
data. */
.tls BLOCK(__section_alignment__) :
{
___tls_start__ = . ;
KEEP (*(.tls$AAA))
KEEP (*(.tls))
KEEP (*(.tls$))
KEEP (*(SORT(.tls$*)))
KEEP (*(.tls$ZZZ))
___tls_end__ = . ;
}
.endjunk BLOCK(__section_alignment__) :
{
/* end is deprecated, don't use it */
PROVIDE (end = .);
PROVIDE ( _end = .);
__end__ = .;
}
.rsrc BLOCK(__section_alignment__) : SUBALIGN(4)
{
KEEP (*(.rsrc))
KEEP (*(.rsrc$*))
}
.reloc BLOCK(__section_alignment__) :
{
*(.reloc)
}
...
}
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: mode i386pep
attempt to open C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/crt2.o succeeded
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/crt2.o
attempt to open C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtbegin.o succeeded
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/crtbegin.o
attempt to open C:\Users\username\AppData\Local\Temp\ccDaML7J.o succeeded
C:\Users\username\AppData\Local\Temp\ccDaML7J.o
attempt to open C:\msys64\mingw64\lib\libcurl.a succeeded
C:\msys64\mingw64\lib\libcurl.a
attempt to open C:\msys64\mingw64\lib\libregex.a succeeded
C:\msys64\mingw64\lib\libregex.a
(C:\msys64\mingw64\lib\libregex.a)systre.o
attempt to open C:\msys64\mingw64\lib\libsqlite3.a succeeded
C:\msys64\mingw64\lib\libsqlite3.a
(C:\msys64\mingw64\lib\libsqlite3.a)sqlite3.o
attempt to open C:\msys64\mingw64\lib\libssl.a succeeded
C:\msys64\mingw64\lib\libssl.a
attempt to open C:\msys64\mingw64\lib\libjansson.a succeeded
C:\msys64\mingw64\lib\libjansson.a
(C:\msys64\mingw64\lib\libjansson.a)load.o
(C:\msys64\mingw64\lib\libjansson.a)memory.o
(C:\msys64\mingw64\lib\libjansson.a)strbuffer.o
(C:\msys64\mingw64\lib\libjansson.a)strconv.o
(C:\msys64\mingw64\lib\libjansson.a)utf.o
(C:\msys64\mingw64\lib\libjansson.a)value.o
(C:\msys64\mingw64\lib\libjansson.a)error.o
(C:\msys64\mingw64\lib\libjansson.a)hashtable.o
(C:\msys64\mingw64\lib\libjansson.a)hashtable_seed.o
attempt to open C:\msys64\mingw64\lib\libiphlpapi.a succeeded
C:\msys64\mingw64\lib\libiphlpapi.a
attempt to open C:\msys64\mingw64\lib\libcrypto.a succeeded
C:\msys64\mingw64\lib\libcrypto.a
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-e_aes.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-encode.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-evp_enc.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-evp_fetch.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-evp_lib.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-evp_utils.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-pmeth_gn.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-pmeth_lib.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-signature.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-context.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-core_algorithm.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-core_fetch.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-core_namemap.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-cryptlib.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-ex_data.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-init.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-initthread.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-mem.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-mem_sec.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-o_str.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-params.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-params_dup.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-provider_child.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-provider_conf.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-provider_core.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-provider_predefined.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-self_test_core.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-threads_win.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-trace.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-x86_64cpuid.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-aesni-gcm-x86_64.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-cbc128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-ccm128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-cfb128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-ctr128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-gcm128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-ghash-x86_64.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-ocb128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-ofb128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-wrap128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-xts128.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-o_names.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-obj_dat.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-obj_lib.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-obj_xref.obj
(C:\msys64\mingw64\lib\libcrypto.a)libcrypto-lib-defn_cache.obj
attempt to open C:\msys64\mingw64\lib\libmingw32.a succeeded
C:\msys64\mingw64\lib\libmingw32.a
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-gccmain.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-natstart.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-wildcard.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-dllargv.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-_newmode.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-tlssup.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-xncommod.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-cinitexe.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-merr.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-CRT_fp10.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-mingw_helpers.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-pseudo-reloc.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-usermatherr.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-xtxtmode.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-crt_handler.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-tlsthrd.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-tlsmcrt.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-pseudo-reloc-list.o
(C:\msys64\mingw64\lib\libmingw32.a)lib64_libmingw32_a-pesect.o
attempt to open C:\msys64\mingw64\lib\libgcc.a failed
attempt to open C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0\libgcc.a succeeded
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0\libgcc.a
(C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0\libgcc.a)_chkstk_ms.o
(C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0\libgcc.a)_ctors.o
attempt to open C:\msys64\mingw64\lib\libgcc_eh.a failed
attempt to open C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0\libgcc_eh.a succeeded
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0\libgcc_eh.a
attempt to open C:\msys64\mingw64\lib\libmoldname.a succeeded
使用 -l:libcurl.a:
C:\Users\__\testing>gcc main.c -o main.exe -static -l:libcurl.a -lregex -lsqlite3 -lssl -ljansson -liphlpapi -lcrypto -lcrypt32 -w -mwindows
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccDreVpm.o:main.c:(.text+0x3ec): undefined reference to `__imp_curl_global_init'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\username\AppData\Local\Temp\ccDreVpm.o:main.c:(.text+0x403): undefined reference to `__imp_curl_easy_init'
...
答: 暂无答案
评论
gcc: error: unrecognized command-line option '-Wl'; did you mean '-W'?
warning: MPFR header version 4.2.0-p12 differs from library version 4.2.1.
看起来很可疑。