Skip to content

Commit 4640853

Browse files
committed
on linux, link statically if not linking any shared libs
1 parent 8700f4d commit 4640853

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/link.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ static void construct_linker_job_elf(LinkJob *lj) {
215215
lj->args.append(getLDMOption(&g->zig_target));
216216

217217
bool is_lib = g->out_type == OutTypeLib;
218-
bool shared = !g->is_static && is_lib;
218+
bool is_static = g->is_static || (!is_lib && g->link_libs_list.length == 0);
219+
bool shared = !is_static && is_lib;
219220
Buf *soname = nullptr;
220-
if (g->is_static) {
221+
if (is_static) {
221222
if (g->zig_target.arch.arch == ZigLLVM_arm || g->zig_target.arch.arch == ZigLLVM_armeb ||
222223
g->zig_target.arch.arch == ZigLLVM_thumb || g->zig_target.arch.arch == ZigLLVM_thumbeb)
223224
{
@@ -241,7 +242,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
241242
if (lj->link_in_crt) {
242243
const char *crt1o;
243244
const char *crtbegino;
244-
if (g->is_static) {
245+
if (is_static) {
245246
crt1o = "crt1.o";
246247
crtbegino = "crtbeginT.o";
247248
} else {
@@ -292,7 +293,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
292293
lj->args.append(buf_ptr(g->libc_static_lib_dir));
293294
}
294295

295-
if (!g->is_static) {
296+
if (!is_static) {
296297
if (g->dynamic_linker != nullptr) {
297298
assert(buf_len(g->dynamic_linker) != 0);
298299
lj->args.append("-dynamic-linker");
@@ -344,7 +345,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
344345

345346
// libc dep
346347
if (g->libc_link_lib != nullptr) {
347-
if (g->is_static) {
348+
if (is_static) {
348349
lj->args.append("--start-group");
349350
lj->args.append("-lgcc");
350351
lj->args.append("-lgcc_eh");

0 commit comments

Comments
 (0)