更新时间:2023-10-18 19:43:52
GCC's -static
option, which you are applying, is non-positional. It enforces
static linkage of all libraries. Your linkage then fails because your system has no static version of libcrt0.o
您可能将GCC的static
选项与 ld
的-static
选项(同义词:-Bstatic
,-dn
-non_shared
),
是位置.它仅影响命令行上的后续库.这是逆的
链接器的-Bdynamic
选项(同义词:-dy
,-call_shared
).
You may be confusing GCC's static
option with ld
's -static
option (synonyms: -Bstatic
, -dn
-non_shared
),
which is positional. It affects only subsequent libraries on the commandline. It is the inverse of
the linker's -Bdynamic
option (synonyms: -dy
, -call_shared
).
因此,仅通过GCC静态链接库-lfoo
,-lbar
...,您可以将-Bstatic
传递给
链接器(在您提及它们之前)和-Bdynamic
在它们之后:
So to link only libraries -lfoo
, -lbar
... statically, via GCC, you can pass -Bstatic
through to the
linker just before you mention them and -Bdynamic
just after them:
-Wl,-Bstatic -lfoo -lbar -Wl,-Bdynamic
即使-lbar
是您的最后一个库,也不要省略最后一个-Wl,-Bdynamic
,因为GCC会悄悄地附加标准库
到您的链接(如您所见).
Do not omit the final -Wl,-Bdynamic
, even if -lbar
is the last of your libraries, because GCC quietly appends standard libraries
to your linkage (as you have found).